<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span>  * GREUtils - is simple and easy use APIs libraries for GRE (Gecko Runtime Environment).
<span class='line'>  3</span>  *
<span class='line'>  4</span>  * Copyright (c) 2007 Rack Lin (racklin@gmail.com)
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * $Date: 2008-08-18 10:25:28 +0800 (星期一, 18 八月 2008) $
<span class='line'>  7</span>  * $Rev: 9 $
<span class='line'>  8</span>  */</span><span class="WHIT">
<span class='line'>  9</span> </span><span class="COMM">/**
<span class='line'> 10</span>  * GREUtils - A set of convenience packages and functions useful for developing applications for
<span class='line'> 11</span>  * the Gecko Runtime Environment (XULRunner / FireFox).
<span class='line'> 12</span>  * 
<span class='line'> 13</span>  * @public
<span class='line'> 14</span>  * @name GREUtils
<span class='line'> 15</span>  * @namespace GREUtils
<span class='line'> 16</span>  */</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">GREUtils</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils</span><span class="WHIT">  </span><span class="PUNC">||</span><span class="WHIT">  </span><span class="PUNC">{</span><span class="NAME">version</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"1.1"</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 18</span> 
<span class='line'> 19</span> </span><span class="NAME">GREUtils.context</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 20</span> 
<span class='line'> 21</span> </span><span class="NAME">GREUtils.global</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">window</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">window</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 22</span> 
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="COMM">/**
<span class='line'> 25</span>  * Extends an object by merging properties from other objects.
<span class='line'> 26</span>  * 
<span class='line'> 27</span>  * Properties in the target object (the object being extended) are overridden by
<span class='line'> 28</span>  * properties from the objects used for extending the target object.  
<span class='line'> 29</span>  *
<span class='line'> 30</span>  * @public
<span class='line'> 31</span>  * @static
<span class='line'> 32</span>  * @function
<span class='line'> 33</span>  * @param {Object} target                     This is the object being extended
<span class='line'> 34</span>  * @param {Object} source                     This is the object used to extend the target
<span class='line'> 35</span>  * @param {Object} extras                     This object, if provided, is also used to extend the target
<span class='line'> 36</span>  * @return {Object}                           The original but modified object
<span class='line'> 37</span>  */</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="NAME">GREUtils.extend</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 39</span>     </span><span class="COMM">// copy reference to target object</span><span class="WHIT">
<span class='line'> 40</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 42</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">extras</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 43</span> 
<span class='line'> 44</span>     </span><span class="COMM">// Extend the base object</span><span class="WHIT">
<span class='line'> 45</span>     </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 46</span>         </span><span class="COMM">// Prevent never-ending loop</span><span class="WHIT">
<span class='line'> 47</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 48</span>             </span><span class="KEYW">continue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span>         </span><span class="COMM">// Don't bring in undefined values</span><span class="WHIT">
<span class='line'> 51</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 52</span>             </span><span class="NAME">target</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 54</span> 
<span class='line'> 55</span>     </span><span class="COMM">// Extend the extra object</span><span class="WHIT">
<span class='line'> 56</span>     </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">extras</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span>         </span><span class="COMM">// Prevent never-ending loop</span><span class="WHIT">
<span class='line'> 58</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">extras</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 59</span>             </span><span class="KEYW">continue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> 
<span class='line'> 61</span>         </span><span class="COMM">// Don't bring in undefined values</span><span class="WHIT">
<span class='line'> 62</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">extras</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 63</span>             </span><span class="NAME">target</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">extras</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 65</span> 
<span class='line'> 66</span>     </span><span class="COMM">// Return the modified object</span><span class="WHIT">
<span class='line'> 67</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> 
<span class='line'> 70</span> 
<span class='line'> 71</span> </span><span class="COMM">/**
<span class='line'> 72</span>  *  Extends any object or function with a getInstance() method to support the
<span class='line'> 73</span>  *  Singleton pattern. Invoking the getInstance() method on the extended
<span class='line'> 74</span>  *  target will always return the same instance of the target.
<span class='line'> 75</span>  *  
<span class='line'> 76</span>  *  The intent of the Singleton pattern as defined in Design Patterns is to
<span class='line'> 77</span>  *  "ensure a class has only one instance, and provide a global point of access to it".
<span class='line'> 78</span>  *
<span class='line'> 79</span>  * @public
<span class='line'> 80</span>  * @static
<span class='line'> 81</span>  * @function
<span class='line'> 82</span>  * @param {Object|Function} target            This is the object or function to extend to support Singleton pattern
<span class='line'> 83</span>  */</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="NAME">GREUtils.singleton</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 85</span> 	
<span class='line'> 86</span> 	</span><span class="NAME">GREUtils.extend</span><span class="PUNC">(</span><span class="NAME">target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 87</span> 	    </span><span class="NAME">__instance__</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">//define the static property</span><span class="WHIT">
<span class='line'> 88</span> 	    
<span class='line'> 89</span> 		</span><span class="COMM">// return single instance</span><span class="WHIT">
<span class='line'> 90</span> 	    </span><span class="NAME">getInstance</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getInstance</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 91</span> 	    
<span class='line'> 92</span> 	        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.__instance__</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 93</span> 	            </span><span class="NAME">this.__instance__</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> 	        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 95</span> 	        
<span class='line'> 96</span> 	        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.__instance__</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 97</span> 	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 98</span> 	</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>100</span> 
<span class='line'>101</span> 
<span class='line'>102</span> </span><span class="COMM">/**
<span class='line'>103</span>  * Establishes an inheritance relationship between two classes.
<span class='line'>104</span>  * 
<span class='line'>105</span>  * The child class inherits methods and attributes from the parent class. After
<span class='line'>106</span>  * inheritance has been established, instance of the child class can use
<span class='line'>107</span>  * this._super to call parent methods.
<span class='line'>108</span>  * 
<span class='line'>109</span>  * @public
<span class='line'>110</span>  * @static
<span class='line'>111</span>  * @function
<span class='line'>112</span>  * @param {Function} childFunc                This is the child class.
<span class='line'>113</span>  * @param {Function} parentFunc               This is the parent class.
<span class='line'>114</span>  */</span><span class="WHIT">
<span class='line'>115</span> </span><span class="NAME">GREUtils.inherits</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">childFunc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">parentFunc</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>116</span> 
<span class='line'>117</span> 	</span><span class="COMM">// The dummy class constructor</span><span class="WHIT">
<span class='line'>118</span>     </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">Class</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> 	
<span class='line'>120</span> 	</span><span class="COMM">// Populate our constructed prototype object</span><span class="WHIT">
<span class='line'>121</span>     </span><span class="NAME">Class.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parentFunc.prototype</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>122</span> 	
<span class='line'>123</span> 	</span><span class="COMM">// Add a new ._super that is the super-class</span><span class="WHIT">
<span class='line'>124</span>     </span><span class="NAME">childFunc._super</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parentFunc.prototype</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>125</span> 	
<span class='line'>126</span>     </span><span class="NAME">childFunc.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Class</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>127</span> 	
<span class='line'>128</span> 	</span><span class="COMM">// Enforce the constructor to be what we expect</span><span class="WHIT">
<span class='line'>129</span>     </span><span class="NAME">childFunc.prototype.constructor</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">childFunc</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span>     
<span class='line'>131</span>     </span><span class="COMM">// auto support singleton if parent getInstance exists</span><span class="WHIT">
<span class='line'>132</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">parentFunc.getInstance</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</span>         </span><span class="NAME">GREUtils.singleton</span><span class="PUNC">(</span><span class="NAME">childFunc</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>135</span> 
<span class='line'>136</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>137</span> 
<span class='line'>138</span> 
<span class='line'>139</span> </span><span class="COMM">/**
<span class='line'>140</span>  * Creates a namespace, optionally associating a context with the namespace.
<span class='line'>141</span>  * 
<span class='line'>142</span>  * @public
<span class='line'>143</span>  * @static
<span class='line'>144</span>  * @function
<span class='line'>145</span>  * @param {Function} name                     This is the name of the namespace
<span class='line'>146</span>  * @param {Function} context                  This is the namespace context; defaults to the global context
<span class='line'>147</span>  */</span><span class="WHIT">
<span class='line'>148</span> </span><span class="NAME">GREUtils.define</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>149</span> 
<span class='line'>150</span>   </span><span class="NAME">GREUtils.createNamespace</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> 
<span class='line'>152</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>153</span> 
<span class='line'>154</span> 
<span class='line'>155</span> </span><span class="COMM">/**
<span class='line'>156</span>  * Using a namespace, optionally associating a context with the namespace.
<span class='line'>157</span>  * 
<span class='line'>158</span>  * @public
<span class='line'>159</span>  * @static
<span class='line'>160</span>  * @function
<span class='line'>161</span>  * @param {Function} name                     This is the name of the namespace
<span class='line'>162</span>  * @param {Function} context                  This is the namespace context; defaults to the global context
<span class='line'>163</span>  */</span><span class="WHIT">
<span class='line'>164</span> </span><span class="NAME">GREUtils.using</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>165</span> 
<span class='line'>166</span>   </span><span class="NAME">GREUtils.createNamespace</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT">  </span><span class="NAME">GREUtils.getObjectByNamespace</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> 
<span class='line'>168</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> 
<span class='line'>170</span> 
<span class='line'>171</span> </span><span class="COMM">/**
<span class='line'>172</span>  * Builds an object structure for the provided namespace path,
<span class='line'>173</span>  * example:
<span class='line'>174</span>  * "a.b.c" -> a = {};a.b={};a.b.c={};
<span class='line'>175</span>  * Used by GREUtils.namespace
<span class='line'>176</span>  * 
<span class='line'>177</span>  * @private
<span class='line'>178</span>  * @function
<span class='line'>179</span>  * @static
<span class='line'>180</span>  * @param {string} name 			Name of the object that this file defines.
<span class='line'>181</span>  * @param {Object} object 			Object to expose at the end of the path.
<span class='line'>182</span>  * @param {Object} context			Create Namespace in context.
<span class='line'>183</span>  */</span><span class="WHIT">
<span class='line'>184</span> </span><span class="NAME">GREUtils.createNamespace</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">object</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>185</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parts</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">name.split</span><span class="PUNC">(</span><span class="STRN">'.'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">GREUtils.global</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>187</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">part</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>188</span> 
<span class='line'>189</span>   </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">part</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parts.shift</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>190</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">parts.length</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">GREUtils.isDefined</span><span class="PUNC">(</span><span class="NAME">object</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>191</span>       </span><span class="COMM">// last part and we have an object; use it</span><span class="WHIT">
<span class='line'>192</span>       </span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">object</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>193</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>194</span>       </span><span class="NAME">cur</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>195</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>196</span>       </span><span class="NAME">cur</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>197</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>198</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>199</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>200</span> 
<span class='line'>201</span> </span><span class="COMM">/**
<span class='line'>202</span>  * Returns an object based on its fully qualified name (by GREUtils.createNamespace)
<span class='line'>203</span>  *
<span class='line'>204</span>  * @param {Object} name  The fully qualified name.
<span class='line'>205</span>  * @param {Object} context
<span class='line'>206</span>  * @return {Object?} The object or, if not found, null. 
<span class='line'>207</span>  */</span><span class="WHIT">
<span class='line'>208</span> </span><span class="NAME">GREUtils.getObjectByNamespace</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">context</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>209</span> 	
<span class='line'>210</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parts</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">name.split</span><span class="PUNC">(</span><span class="STRN">'.'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>211</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">context</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">GREUtils.global</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>212</span>   
<span class='line'>213</span>   </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">part</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">part</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parts.shift</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>214</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>215</span>       </span><span class="NAME">cur</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="PUNC">[</span><span class="NAME">part</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>216</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>217</span>       </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>218</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>219</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>220</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">cur</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>221</span> 
<span class='line'>222</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>223</span> 
<span class='line'>224</span> 
<span class='line'>225</span> </span><span class="COMM">/**
<span class='line'>226</span>  * Checks if the type is defined
<span class='line'>227</span>  * 
<span class='line'>228</span>  * @public
<span class='line'>229</span>  * @static
<span class='line'>230</span>  * @function
<span class='line'>231</span>  * @param {String} type           			This is the value to check
<span class='line'>232</span>  * @return {Boolean}            			"true" if parameter is defined; "false" otherwise
<span class='line'>233</span>  */</span><span class="WHIT">
<span class='line'>234</span> </span><span class="NAME">GREUtils.isDefined</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>235</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>236</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>237</span> 
<span class='line'>238</span> 
<span class='line'>239</span> </span><span class="COMM">/**
<span class='line'>240</span>  * Checks if the type is function.
<span class='line'>241</span>  * 
<span class='line'>242</span>  * @public
<span class='line'>243</span>  * @static
<span class='line'>244</span>  * @function
<span class='line'>245</span>  * @param {Object|Function} type			This is the value to check
<span class='line'>246</span>  * @return {Boolean}						"true" if the value is a function; "false" otherwise
<span class='line'>247</span>  */</span><span class="WHIT">
<span class='line'>248</span> </span><span class="NAME">GREUtils.isFunction</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>249</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"function"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>250</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>251</span> 
<span class='line'>252</span> 
<span class='line'>253</span> </span><span class="COMM">/**
<span class='line'>254</span>  * Checks if the value is null.
<span class='line'>255</span>  * 
<span class='line'>256</span>  * @public
<span class='line'>257</span>  * @static
<span class='line'>258</span>  * @function
<span class='line'>259</span>  * @param {Object} type           This is the value to check
<span class='line'>260</span>  * @return {Boolean}              "true" if the value is null; "false" otherwise
<span class='line'>261</span>  */</span><span class="WHIT">
<span class='line'>262</span> </span><span class="NAME">GREUtils.isNull</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>263</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>264</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>265</span> 
<span class='line'>266</span> 
<span class='line'>267</span> </span><span class="COMM">/**
<span class='line'>268</span>  * Checks if the value is defined and not null.
<span class='line'>269</span>  * 
<span class='line'>270</span>  * @public
<span class='line'>271</span>  * @static
<span class='line'>272</span>  * @function
<span class='line'>273</span>  * @param {Object} type			          This is the value to check
<span class='line'>274</span>  * @return {Boolean}                      "true" if the value is defined and not null; "false" otherwise
<span class='line'>275</span>  */</span><span class="WHIT">
<span class='line'>276</span> </span><span class="NAME">GREUtils.isDefineAndNotNull</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>277</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.isDefined</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">GREUtils.isNull</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>278</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>279</span> 
<span class='line'>280</span> 
<span class='line'>281</span> </span><span class="COMM">/**
<span class='line'>282</span>  * Checks if the value is an array.
<span class='line'>283</span>  * 
<span class='line'>284</span>  * @public
<span class='line'>285</span>  * @static
<span class='line'>286</span>  * @function
<span class='line'>287</span>  * @param {Object} type           This is the value to check
<span class='line'>288</span>  * @return {Boolean}              "true" if the value is an array; "false" otherwise
<span class='line'>289</span>  */</span><span class="WHIT">
<span class='line'>290</span> </span><span class="NAME">GREUtils.isArray</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>291</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'array'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>292</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>293</span> 
<span class='line'>294</span> </span><span class="COMM">/**
<span class='line'>295</span>  * Checks if the value is a string.
<span class='line'>296</span>  * 
<span class='line'>297</span>  * @public
<span class='line'>298</span>  * @static
<span class='line'>299</span>  * @function
<span class='line'>300</span>  * @param {Object} type           This is the value to check
<span class='line'>301</span>  * @return {Boolean}              "true" if the value is a string; "false" otherwise
<span class='line'>302</span>  */</span><span class="WHIT">
<span class='line'>303</span> </span><span class="NAME">GREUtils.isString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>304</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>305</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>306</span> 
<span class='line'>307</span> 
<span class='line'>308</span> </span><span class="COMM">/**
<span class='line'>309</span>  * Checks if the value is a boolean.
<span class='line'>310</span>  * 
<span class='line'>311</span>  * @public
<span class='line'>312</span>  * @static
<span class='line'>313</span>  * @function
<span class='line'>314</span>  * @param {Object} type           This is the value to check
<span class='line'>315</span>  * @return {Boolean}              "true" if the value is a boolean; "false" otherwise
<span class='line'>316</span>  */</span><span class="WHIT">
<span class='line'>317</span> </span><span class="NAME">GREUtils.isBoolean</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>318</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'boolean'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>319</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>320</span> 
<span class='line'>321</span> 
<span class='line'>322</span> </span><span class="COMM">/**
<span class='line'>323</span>  * Checks if the value is a number.
<span class='line'>324</span>  * 
<span class='line'>325</span>  * @public
<span class='line'>326</span>  * @static
<span class='line'>327</span>  * @function
<span class='line'>328</span>  * @param {String} type           This is the value to check
<span class='line'>329</span>  * @return {Boolean}              "true" if the value is a number; "false" otherwise
<span class='line'>330</span>  */</span><span class="WHIT">
<span class='line'>331</span> </span><span class="NAME">GREUtils.isNumber</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>332</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'number'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>334</span> 
<span class='line'>335</span> 
<span class='line'>336</span> </span><span class="COMM">/**
<span class='line'>337</span>  * Checks if the value is an object (including functions and arrays).
<span class='line'>338</span>  * 
<span class='line'>339</span>  * @public
<span class='line'>340</span>  * @static
<span class='line'>341</span>  * @function
<span class='line'>342</span>  * @param {String} type           This is the value to check
<span class='line'>343</span>  * @return {Boolean}              "true" if the value is an object; "false" otherwise
<span class='line'>344</span>  */</span><span class="WHIT">
<span class='line'>345</span> </span><span class="NAME">GREUtils.isObject</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>346</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">type</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>347</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'array'</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>348</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>349</span> 
<span class='line'>350</span> </span><span class="COMM">/**
<span class='line'>351</span>  * Gets the current time.
<span class='line'>352</span>  * 
<span class='line'>353</span>  * This method returns the current time expressed as the number of milliseconds since
<span class='line'>354</span>  * January 1, 1970, 00:00:00 UTC.
<span class='line'>355</span>  * 
<span class='line'>356</span>  * @public
<span class='line'>357</span>  * @static
<span class='line'>358</span>  * @function
<span class='line'>359</span>  * @return {Number}                       The current time
<span class='line'>360</span>  */</span><span class="WHIT">
<span class='line'>361</span> </span><span class="NAME">GREUtils.now</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Date.now</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>362</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>363</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>364</span> </span><span class="COMM">/**
<span class='line'>365</span>  * A set of utility functions for accessing XPCOM component interfaces and services.
<span class='line'>366</span>  *
<span class='line'>367</span>  * @public
<span class='line'>368</span>  * @name GREUtils.XPCOM
<span class='line'>369</span>  * @namespace GREUtils.XPCOM
<span class='line'>370</span>  */</span><span class="WHIT">
<span class='line'>371</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.XPCOM'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>372</span> 
<span class='line'>373</span> </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>374</span>     </span><span class="COMM">// try assign Components.classes for privilege check // shortcut by exception :D</span><span class="WHIT">
<span class='line'>375</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">_CC</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Components.classes</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>376</span>     </span><span class="NAME">GREUtils.XPCOM._EnablePrivilege</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>377</span> </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>378</span>     </span><span class="COMM">// need Privilege and any XPCOM Operation need enablePrivilege.</span><span class="WHIT">
<span class='line'>379</span>     </span><span class="COMM">// netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");</span><span class="WHIT">
<span class='line'>380</span>     </span><span class="NAME">GREUtils.XPCOM._EnablePrivilege</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>381</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>382</span> 
<span class='line'>383</span> </span><span class="COMM">/**
<span class='line'>384</span>  * Returns the XPCOM component by class name.
<span class='line'>385</span>  *
<span class='line'>386</span>  * This method returns null if the component is not found (i.e. component name does
<span class='line'>387</span>  * not exist in Components.classes[]).
<span class='line'>388</span>  *
<span class='line'>389</span>  * @public
<span class='line'>390</span>  * @static
<span class='line'>391</span>  * @function
<span class='line'>392</span>  * @param {String} cName        This is the name of the XPCOM component
<span class='line'>393</span>  * @return {Object}             The XPCOM component
<span class='line'>394</span>  * @type                        Object
<span class='line'>395</span>  */</span><span class="WHIT">
<span class='line'>396</span> </span><span class="NAME">GREUtils.XPCOM.Cc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>397</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>398</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">cName</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">Components.classes</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Components.classes</span><span class="PUNC">[</span><span class="NAME">cName</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>399</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>400</span>     </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>401</span>         </span><span class="COMM">// netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");</span><span class="WHIT">
<span class='line'>402</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.Cc: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>403</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>404</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>405</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>406</span> 
<span class='line'>407</span> </span><span class="COMM">/**
<span class='line'>408</span>  * Returns the XPCOM interface by interface name.
<span class='line'>409</span>  *
<span class='line'>410</span>  * This method returns null if the interface is not found (i.e. interface name does
<span class='line'>411</span>  * not exist in Components.interfaces[]). If an object is passed in as
<span class='line'>412</span>  * parameter "ifaceName" then this object is returned.
<span class='line'>413</span>  *
<span class='line'>414</span>  * @public
<span class='line'>415</span>  * @static
<span class='line'>416</span>  * @function
<span class='line'>417</span>  * @param {String} ifaceName    This is the name of the XPCOM interface
<span class='line'>418</span>  * @return {Object}             The XPCOM interface
<span class='line'>419</span>  * @type                        Object
<span class='line'>420</span>  */</span><span class="WHIT">
<span class='line'>421</span> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>422</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>423</span>         </span><span class="KEYW">switch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>424</span>             </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>425</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">ifaceName</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>426</span>                 </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>427</span> 
<span class='line'>428</span>             </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>429</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Components.interfaces</span><span class="PUNC">[</span><span class="NAME">ifaceName</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>430</span>                 </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>431</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>432</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>433</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.Ci: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>434</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>435</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>436</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>437</span> 
<span class='line'>438</span> 
<span class='line'>439</span> </span><span class="COMM">/**
<span class='line'>440</span>  * Returns the Components.results object whose properties are the names of well-known
<span class='line'>441</span>  * XPCOM result codes, with each value being that of the corresponding result code.
<span class='line'>442</span>  * Elements in this array can be used to test against unknown nsresult variables or
<span class='line'>443</span>  * they can be 'thrown' to indicate failure.
<span class='line'>444</span>  *
<span class='line'>445</span>  * @public
<span class='line'>446</span>  * @static
<span class='line'>447</span>  * @function
<span class='line'>448</span>  * @return {Array}              List of well known XPCOM result codes
<span class='line'>449</span>  * @type                        Object
<span class='line'>450</span>  */</span><span class="WHIT">
<span class='line'>451</span> </span><span class="NAME">GREUtils.XPCOM.Cr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>452</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>453</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Components.results</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>454</span>     </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>455</span>         </span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.Cr: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>456</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>457</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>458</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>459</span> 
<span class='line'>460</span> 
<span class='line'>461</span> </span><span class="COMM">/**
<span class='line'>462</span>  * Returns an XPCOM service.
<span class='line'>463</span>  *
<span class='line'>464</span>  * This method returns the XPCOM service identified by its Component class and interface
<span class='line'>465</span>  * name. If the service does not exist, null is returned.
<span class='line'>466</span>  *
<span class='line'>467</span>  * @public
<span class='line'>468</span>  * @static
<span class='line'>469</span>  * @function
<span class='line'>470</span>  * @param {String} cName        This is the name of the XPCOM component
<span class='line'>471</span>  * @param {String} iName        This is the name of the XPCOM interface; can be null
<span class='line'>472</span>  * @return {Object}             The XPCOM service
<span class='line'>473</span>  * @type                        Object
<span class='line'>474</span>  */</span><span class="WHIT">
<span class='line'>475</span> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>476</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cls</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cc</span><span class="PUNC">(</span><span class="NAME">cName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>477</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">iface</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="PUNC">(</span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>478</span> 
<span class='line'>479</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>480</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cls</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">iface</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>481</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">cls.getService</span><span class="PUNC">(</span><span class="NAME">iface</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>482</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>483</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cls</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>484</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">cls.getService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>485</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>486</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>487</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>488</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>489</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.getService: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>490</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>491</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>492</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>493</span> 
<span class='line'>494</span> 
<span class='line'>495</span> </span><span class="COMM">/**
<span class='line'>496</span>  * Returns an XPCOM instance.
<span class='line'>497</span>  *
<span class='line'>498</span>  * This method returns an instance of an XPCOM component with a given interface name.
<span class='line'>499</span>  * If the component or the interface does not exist, or if the instantiation fails,
<span class='line'>500</span>  * then null is returned.
<span class='line'>501</span>  *
<span class='line'>502</span>  * @public
<span class='line'>503</span>  * @static
<span class='line'>504</span>  * @function
<span class='line'>505</span>  * @param {String} cName        This is the name of the XPCOM component
<span class='line'>506</span>  * @param {String} iName        This is the name of the XPCOM interface
<span class='line'>507</span>  * @return {Object}             An instance of the XPCOM component with the given interface
<span class='line'>508</span>  * @type                        Object
<span class='line'>509</span>  */</span><span class="WHIT">
<span class='line'>510</span> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>511</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cls</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cc</span><span class="PUNC">(</span><span class="NAME">cName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>512</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">iface</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="PUNC">(</span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>513</span> 
<span class='line'>514</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>515</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">cls</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">iface</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>516</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">cls.createInstance</span><span class="PUNC">(</span><span class="NAME">iface</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>517</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>518</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>519</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>520</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.createInstance: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>521</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>522</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>523</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>524</span> 
<span class='line'>525</span> 
<span class='line'>526</span> </span><span class="COMM">/**
<span class='line'>527</span>  * Retrieves a specific interface of an instance of XPCOM component.
<span class='line'>528</span>  *
<span class='line'>529</span>  * This method gets the specified interface for an instance of an XPCOM component
<span class='line'>530</span>  * if the interface is supported by the component. Otherwise null is returned.
<span class='line'>531</span>  *
<span class='line'>532</span>  * If the
<span class='line'>533</span>  * @public
<span class='line'>534</span>  * @static
<span class='line'>535</span>  * @function
<span class='line'>536</span>  * @param {Object} obj          This is an instance of XPCOM component
<span class='line'>537</span>  * @param {String} ifaceName    This is the name of the XPCOM interface
<span class='line'>538</span>  * @return {Object}             The XPCOM component instance with the specified interface
<span class='line'>539</span>  * @type                        Object
<span class='line'>540</span>  */</span><span class="WHIT">
<span class='line'>541</span> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">obj</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>542</span> 
<span class='line'>543</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">obj</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>544</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">iface</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="PUNC">(</span><span class="NAME">ifaceName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>545</span> 		</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>546</span> 		  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">iface</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj.QueryInterface</span><span class="PUNC">(</span><span class="NAME">iface</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>547</span> 		</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>548</span> 			</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.queryInterface: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>549</span> 		  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>550</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>551</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>552</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>553</span> 
<span class='line'>554</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>555</span> 
<span class='line'>556</span> 
<span class='line'>557</span> </span><span class="COMM">/**
<span class='line'>558</span>  * Creates a JavaScript function which can be used to create or construct new instances
<span class='line'>559</span>  * of XPCOM components.
<span class='line'>560</span>  *
<span class='line'>561</span>  * If an interface is specified, QueryInterface will be called on each newly-created
<span class='line'>562</span>  * instance with this interface.
<span class='line'>563</span>  *
<span class='line'>564</span>  * This method can also accept an optional initializer function (passed in by name),
<span class='line'>565</span>  * which will be called on the newly-created instance, using the arguments provided
<span class='line'>566</span>  * to the created function when called
<span class='line'>567</span>  *
<span class='line'>568</span>  * If the method fails to create the constructor function, null is returned.
<span class='line'>569</span>  *
<span class='line'>570</span>  * This method is a wrapper for Components.Constructor().
<span class='line'>571</span>  *
<span class='line'>572</span>  * @public
<span class='line'>573</span>  * @static
<span class='line'>574</span>  * @function
<span class='line'>575</span>  * @param {String} aCID         This is the contract ID of an XPCOM component
<span class='line'>576</span>  * @param {String} aInterface   This is the name of the XPCOM interface
<span class='line'>577</span>  * @param {String} aFunc        This is the name of the initializer function
<span class='line'>578</span>  * @return {Object}             An XPCOM component constructor
<span class='line'>579</span>  * @type                        Object
<span class='line'>580</span>  */</span><span class="WHIT">
<span class='line'>581</span> </span><span class="NAME">GREUtils.XPCOM.getConstructor</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aCID</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aInterface</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aFunc</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>582</span>   </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>583</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aFunc</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>584</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Components.Constructor</span><span class="PUNC">(</span><span class="NAME">aCID</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aInterface</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aFunc</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>585</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>586</span> 	</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>587</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Components.Constructor</span><span class="PUNC">(</span><span class="NAME">aCID</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aInterface</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>588</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>589</span>   </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>590</span>       </span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.XPCOM.getConstructor: '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>591</span>   	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>592</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>593</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>594</span> 
<span class='line'>595</span> </span><span class="COMM">/**
<span class='line'>596</span>  * Predefine useful XPCOM Service Name and Interface
<span class='line'>597</span>  *
<span class='line'>598</span>  * @private
<span class='line'>599</span>  * @static
<span class='line'>600</span>  * @field
<span class='line'>601</span>  */</span><span class="WHIT">
<span class='line'>602</span> </span><span class="NAME">GREUtils.XPCOM._usefulServiceMap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>603</span>     </span><span class="STRN">"jssubscript-loader"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/moz/jssubscript-loader;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"mozIJSSubScriptLoader"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>604</span>     </span><span class="STRN">"app-info"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/xre/app-info;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIXULAppInfo"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>605</span>     </span><span class="STRN">"runtime-info"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/xre/app-info;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIXULRuntime"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>606</span>     </span><span class="STRN">"app-startup"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">'@mozilla.org/toolkit/app-startup;1'</span><span class="PUNC">,</span><span class="STRN">'nsIAppStartup'</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>607</span> 	</span><span class="STRN">"sound"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/sound;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsISound"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>608</span>     </span><span class="STRN">"observer-service"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/observer-service;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIObserverService"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>609</span>     </span><span class="STRN">"consoleservice"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/consoleservice;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIConsoleService"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>610</span> 	</span><span class="STRN">"prompt-service"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/embedcomp/prompt-service;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIPromptService"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>611</span> 	</span><span class="STRN">"window-mediator"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/appshell/window-mediator;1"</span><span class="PUNC">,</span><span class="STRN">"nsIWindowMediator"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>612</span> 	</span><span class="STRN">"window-watcher"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/embedcomp/window-watcher;1"</span><span class="PUNC">,</span><span class="STRN">"nsIWindowWatcher"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>613</span> 	</span><span class="STRN">"thread-manager"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/thread-manager;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIThreadManager"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>614</span> 	</span><span class="STRN">"idleservice"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/widget/idleservice;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIIdleService"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>615</span> 	</span><span class="STRN">"json"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/dom/json;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIJSON"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>616</span> 	</span><span class="STRN">"unicodeconverter"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/intl/scriptableunicodeconverter"</span><span class="PUNC">,</span><span class="STRN">"nsIScriptableUnicodeConverter"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>617</span> 	</span><span class="STRN">"hash"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/security/hash;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsICryptoHash"</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>618</span> 	</span><span class="STRN">"xmlhttprequest"</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">"@mozilla.org/xmlextras/xmlhttprequest;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIXMLHttpRequest"</span><span class="PUNC">]</span><span class="WHIT">
<span class='line'>619</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>620</span> 
<span class='line'>621</span> 
<span class='line'>622</span> </span><span class="COMM">/**
<span class='line'>623</span>  * Predefine useful XPCOM Service object pool.
<span class='line'>624</span>  *
<span class='line'>625</span>  * @private
<span class='line'>626</span>  * @static
<span class='line'>627</span>  * @field
<span class='line'>628</span>  */</span><span class="WHIT">
<span class='line'>629</span> </span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>630</span> 
<span class='line'>631</span> 
<span class='line'>632</span> </span><span class="COMM">/**
<span class='line'>633</span>  * Returns commonly used XPCOM services.
<span class='line'>634</span>  *
<span class='line'>635</span>  * This method is a shortcut for retrieving commonly used XPCOM services. Each
<span class='line'>636</span>  * service is identified by an abbreviated name. If the service does not exist,
<span class='line'>637</span>  * null is returned.
<span class='line'>638</span>  *
<span class='line'>639</span>  * The abbreviation scheme is private to GREUtils.
<span class='line'>640</span>  *
<span class='line'>641</span>  * @public
<span class='line'>642</span>  * @static
<span class='line'>643</span>  * @function
<span class='line'>644</span>  * @param {String} serviceName  This is the abbreviated name of the XPCOM service
<span class='line'>645</span>  * @return {Object}             The XPCOM service
<span class='line'>646</span>  * @type                        Object
<span class='line'>647</span>  */</span><span class="WHIT">
<span class='line'>648</span> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">serviceName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>649</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">GREUtils.isXPCOM</span><span class="PUNC">(</span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>650</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>651</span> 
<span class='line'>652</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">serviceName</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM._usefulServiceMap</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>653</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">service</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getService</span><span class="PUNC">(</span><span class="NAME">GREUtils.XPCOM._usefulServiceMap</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM._usefulServiceMap</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>654</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.isXPCOM</span><span class="PUNC">(</span><span class="NAME">service</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>655</span> 			</span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">service</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>656</span> 			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM._usefulServicePool</span><span class="PUNC">[</span><span class="NAME">serviceName</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>657</span> 		</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>658</span> 			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>659</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>660</span> 
<span class='line'>661</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>662</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>663</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>664</span> 
<span class='line'>665</span> 
<span class='line'>666</span> </span><span class="COMM">/**
<span class='line'>667</span>  * Returns true if val is a xpcom components.
<span class='line'>668</span>  *
<span class='line'>669</span>  * XPCom components must implement nsISupports Interface.
<span class='line'>670</span>  *
<span class='line'>671</span>  * @public
<span class='line'>672</span>  * @static
<span class='line'>673</span>  * @function
<span class='line'>674</span>  * @param {Object} val
<span class='line'>675</span>  * @return {Boolean}
<span class='line'>676</span>  */</span><span class="WHIT">
<span class='line'>677</span> </span><span class="NAME">GREUtils.isXPCOM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">val</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>678</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">res</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="PUNC">(</span><span class="NAME">val</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsISupports"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>679</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">res</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">res</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>680</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>681</span> </span><span class="COMM">/*
<span class='line'>682</span>  * Useful Functions
<span class='line'>683</span>  */</span><span class="WHIT">
<span class='line'>684</span> </span><span class="NAME">GREUtils._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>685</span> 
<span class='line'>686</span> 
<span class='line'>687</span> </span><span class="COMM">/**
<span class='line'>688</span>  * Get Application Infomation.
<span class='line'>689</span>  *
<span class='line'>690</span>  * see nsIXULAppInfo Interface.
<span class='line'>691</span>  *
<span class='line'>692</span>  * @public
<span class='line'>693</span>  * @static
<span class='line'>694</span>  * @function 
<span class='line'>695</span>  * @return {Object}
<span class='line'>696</span>  */</span><span class="WHIT">
<span class='line'>697</span> </span><span class="NAME">GREUtils.getAppInfo</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>698</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"app-info"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>699</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>700</span> 
<span class='line'>701</span> 
<span class='line'>702</span> </span><span class="COMM">/**
<span class='line'>703</span>  * Get Runtime Infomation.
<span class='line'>704</span>  *
<span class='line'>705</span>  * see nsIXULRuntime Interface.
<span class='line'>706</span>  *
<span class='line'>707</span>  * @public
<span class='line'>708</span>  * @static
<span class='line'>709</span>  * @function 
<span class='line'>710</span>  * @return {Object}
<span class='line'>711</span>  */</span><span class="WHIT">
<span class='line'>712</span> </span><span class="NAME">GREUtils.getRuntimeInfo</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>713</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"runtime-info"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>714</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>715</span> 
<span class='line'>716</span> 
<span class='line'>717</span> </span><span class="COMM">/**
<span class='line'>718</span>  * Get OS Infomation.
<span class='line'>719</span>  *
<span class='line'>720</span>  * see nsIXULRuntime Interface.
<span class='line'>721</span>  *
<span class='line'>722</span>  * @public
<span class='line'>723</span>  * @static
<span class='line'>724</span>  * @function 
<span class='line'>725</span>  * @return {Object}
<span class='line'>726</span>  */</span><span class="WHIT">
<span class='line'>727</span> </span><span class="NAME">GREUtils.getOSInfo</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>728</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.getRuntimeInfo</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">OS</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>729</span>     
<span class='line'>730</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>731</span> 
<span class='line'>732</span>  
<span class='line'>733</span> </span><span class="COMM">/**
<span class='line'>734</span>  * is Linux OS
<span class='line'>735</span>  *
<span class='line'>736</span>  * @public
<span class='line'>737</span>  * @static
<span class='line'>738</span>  * @function 
<span class='line'>739</span>  * @return {Boolean}
<span class='line'>740</span>  */</span><span class="WHIT">
<span class='line'>741</span> </span><span class="NAME">GREUtils.isLinux</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>742</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.getOSInfo</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/Linux/</span><span class="PUNC">,</span><span class="STRN">"i"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>743</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>744</span> 
<span class='line'>745</span> 
<span class='line'>746</span> </span><span class="COMM">/**
<span class='line'>747</span>  * is Window OS
<span class='line'>748</span>  *
<span class='line'>749</span>  * @public
<span class='line'>750</span>  * @static
<span class='line'>751</span>  * @function 
<span class='line'>752</span>  * @return {Boolean}
<span class='line'>753</span>  */</span><span class="WHIT">
<span class='line'>754</span> </span><span class="NAME">GREUtils.isWindow</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>755</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.getOSInfo</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/Win/</span><span class="PUNC">,</span><span class="STRN">"i"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>756</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>757</span> 
<span class='line'>758</span> 
<span class='line'>759</span> </span><span class="COMM">/**
<span class='line'>760</span>  * is Mac OS
<span class='line'>761</span>  *
<span class='line'>762</span>  * @public
<span class='line'>763</span>  * @static
<span class='line'>764</span>  * @function 
<span class='line'>765</span>  * @return {Boolean}
<span class='line'>766</span>  */</span><span class="WHIT">
<span class='line'>767</span> </span><span class="NAME">GREUtils.isMac</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>768</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.getOSInfo</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/Mac|Darwin/</span><span class="PUNC">,</span><span class="STRN">"i"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>769</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>770</span> 
<span class='line'>771</span> 
<span class='line'>772</span> </span><span class="COMM">/**
<span class='line'>773</span>  * Synchronously loads and executes the script from the specified URL.
<span class='line'>774</span>  *
<span class='line'>775</span>  * default scope is window.
<span class='line'>776</span>  *
<span class='line'>777</span>  * @public
<span class='line'>778</span>  * @static
<span class='line'>779</span>  * @function 
<span class='line'>780</span>  * @param {Object} scriptSrc
<span class='line'>781</span>  * @param {Object} scope
<span class='line'>782</span>  */</span><span class="WHIT">
<span class='line'>783</span> </span><span class="NAME">GREUtils.include</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">scriptSrc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>784</span> 
<span class='line'>785</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">objScope</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">GREUtils.global</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>786</span> 
<span class='line'>787</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">scriptSrc.indexOf</span><span class="PUNC">(</span><span class="STRN">'://'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>788</span>         </span><span class="NAME">scriptSrc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.location.href.substring</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">document.location.href.lastIndexOf</span><span class="PUNC">(</span><span class="STRN">'/'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">scriptSrc</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>789</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>790</span> 
<span class='line'>791</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>792</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>793</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.XPCOM._EnablePrivilege</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">netscape.security.PrivilegeManager.enablePrivilege</span><span class="PUNC">(</span><span class="STRN">"UniversalXPConnect"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>794</span>         </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"jssubscript-loader"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">loadSubScript</span><span class="PUNC">(</span><span class="NAME">scriptSrc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">objScope</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>795</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cr</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">NS_OK</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>796</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>797</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.include: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"("</span><span class="PUNC">+</span><span class="NAME">scriptSrc</span><span class="PUNC">+</span><span class="STRN">")"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>798</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cr</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">NS_ERROR_INVALID_ARG</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>799</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>800</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>801</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>802</span> 
<span class='line'>803</span> 
<span class='line'>804</span> </span><span class="COMM">/**
<span class='line'>805</span>  * Synchronously loads and executes the script from the specified URL.
<span class='line'>806</span>  *
<span class='line'>807</span>  * Specified URL will loads and executes once.
<span class='line'>808</span>  *
<span class='line'>809</span>  * default scope is window.
<span class='line'>810</span>  *
<span class='line'>811</span>  * @public
<span class='line'>812</span>  * @static
<span class='line'>813</span>  * @function 
<span class='line'>814</span>  * @param {Object} scriptSrc
<span class='line'>815</span>  * @param {Object} scope
<span class='line'>816</span>  */</span><span class="WHIT">
<span class='line'>817</span> </span><span class="NAME">GREUtils.include_once</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">scriptSrc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>818</span> 
<span class='line'>819</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptJS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">scriptSrc.substring</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">scriptSrc.lastIndexOf</span><span class="PUNC">(</span><span class="STRN">'/'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scriptSrc.length</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>820</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptJS_loaded</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">encodeURIComponent</span><span class="PUNC">(</span><span class="NAME">scriptJS</span><span class="PUNC">)</span><span class="PUNC">+</span><span class="STRN">"_LOADED"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>821</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">scriptJS_loaded</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">this._data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>822</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cr</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">NS_OK</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>823</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>824</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>825</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.include</span><span class="PUNC">(</span><span class="NAME">scriptSrc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>826</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Cr</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">NS_OK</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>827</span>             </span><span class="NAME">this._data</span><span class="PUNC">[</span><span class="NAME">scriptJS_loaded</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>828</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>829</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>830</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>831</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>832</span> 
<span class='line'>833</span> 
<span class='line'>834</span> </span><span class="COMM">/**
<span class='line'>835</span>  * This method was introduced in Firefox 3.
<span class='line'>836</span>  * Is used for sharing code between different scopes easily.
<span class='line'>837</span>  *
<span class='line'>838</span>  * @public
<span class='line'>839</span>  * @static
<span class='line'>840</span>  * @function 
<span class='line'>841</span>  * @name GREUtils.import
<span class='line'>842</span>  * @param {Object} url
<span class='line'>843</span>  * @param {Object} scope
<span class='line'>844</span>  */</span><span class="WHIT">
<span class='line'>845</span> </span><span class="NAME">GREUtils.import_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>846</span> 
<span class='line'>847</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>848</span> 		</span><span class="NAME">Components.utils</span><span class="PUNC">[</span><span class="STRN">'import'</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">url</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">		
<span class='line'>849</span> 	</span><span class="PUNC">}</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>850</span> 		</span><span class="NAME">Components.utils</span><span class="PUNC">[</span><span class="STRN">'import'</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scope</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>851</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>852</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>853</span> 
<span class='line'>854</span> </span><span class="NAME">GREUtils</span><span class="PUNC">[</span><span class="STRN">'import'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.import_</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>855</span> 
<span class='line'>856</span> </span><span class="COMM">/**
<span class='line'>857</span>  * Convert XUL String to DOM Elements.
<span class='line'>858</span>  *
<span class='line'>859</span>  * XUL String namespace is http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul
<span class='line'>860</span>  * You can specified your custom namespace.
<span class='line'>861</span>  *
<span class='line'>862</span>  * @public
<span class='line'>863</span>  * @static
<span class='line'>864</span>  * @function 
<span class='line'>865</span>  * @param {String} xulString
<span class='line'>866</span>  * @param {String} xmlns
<span class='line'>867</span>  * @return {Object}
<span class='line'>868</span>  */</span><span class="WHIT">
<span class='line'>869</span> </span><span class="NAME">GREUtils.domXULString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">xulString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>870</span> 
<span class='line'>871</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>872</span> 	
<span class='line'>873</span>     </span><span class="COMM">// try with box container and namespace for easy use.</span><span class="WHIT">
<span class='line'>874</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">xulString2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'&lt;box xmlns="'</span><span class="PUNC">+</span><span class="NAME">xmlns</span><span class="PUNC">+</span><span class="STRN">'">'</span><span class="PUNC">+</span><span class="NAME">xulString</span><span class="PUNC">+</span><span class="STRN">'&lt;/box>'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>875</span> 
<span class='line'>876</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parser</span><span class="PUNC">=</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">DOMParser</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>877</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">resultDoc</span><span class="PUNC">=</span><span class="NAME">parser.parseFromString</span><span class="PUNC">(</span><span class="NAME">xulString2</span><span class="PUNC">,</span><span class="STRN">"text/xml"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>878</span> 
<span class='line'>879</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">resultDoc.documentElement.tagName</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"parsererror"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>880</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>881</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>882</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">resultDoc.documentElement.childNodes.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>883</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">resultDoc.documentElement.firstChild</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>884</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>885</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>886</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">resultDoc.documentElement</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>887</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>888</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>889</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>890</span> 
<span class='line'>891</span> 
<span class='line'>892</span> </span><span class="COMM">/**
<span class='line'>893</span>  * Convert HTML String to DOM Elements.
<span class='line'>894</span>  *
<span class='line'>895</span>  * HTML String namespace is http://www.w3.org/1999/xhtml
<span class='line'>896</span>  * You can specified your custom namespace.
<span class='line'>897</span>  *
<span class='line'>898</span>  * @public
<span class='line'>899</span>  * @static
<span class='line'>900</span>  * @function 
<span class='line'>901</span>  * @param {String} htmlString
<span class='line'>902</span>  * @param {String} xmlns
<span class='line'>903</span>  * @return {Object}
<span class='line'>904</span>  */</span><span class="WHIT">
<span class='line'>905</span> </span><span class="NAME">GREUtils.domHTMLString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">htmlString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>906</span> 
<span class='line'>907</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">xmlns</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">"http://www.w3.org/1999/xhtml"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>908</span> 	
<span class='line'>909</span>     </span><span class="COMM">// try with div container and namespace for easy use.</span><span class="WHIT">
<span class='line'>910</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">htmlString2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'&lt;div xmlns="'</span><span class="PUNC">+</span><span class="NAME">xmlns</span><span class="PUNC">+</span><span class="STRN">'">'</span><span class="PUNC">+</span><span class="NAME">htmlString</span><span class="PUNC">+</span><span class="STRN">'&lt;/div>'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>911</span> 
<span class='line'>912</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parser</span><span class="PUNC">=</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">DOMParser</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>913</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">resultDoc</span><span class="PUNC">=</span><span class="NAME">parser.parseFromString</span><span class="PUNC">(</span><span class="NAME">htmlString2</span><span class="PUNC">,</span><span class="STRN">"text/xml"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>914</span> 	
<span class='line'>915</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">resultDoc.documentElement.tagName</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"parsererror"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>916</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>917</span> 	</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>918</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">resultDoc.documentElement.childNodes.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>919</span> 			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">resultDoc.documentElement.firstChild</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>920</span> 		</span><span class="KEYW">else</span><span class="WHIT"> 
<span class='line'>921</span> 			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">resultDoc.documentElement</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>922</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>923</span> 
<span class='line'>924</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>925</span> 
<span class='line'>926</span> 
<span class='line'>927</span> </span><span class="COMM">/**
<span class='line'>928</span>  * Quit Application
<span class='line'>929</span>  *
<span class='line'>930</span>  * see nsIAppStartup
<span class='line'>931</span>  *
<span class='line'>932</span>  * @public
<span class='line'>933</span>  * @static
<span class='line'>934</span>  * @function 
<span class='line'>935</span>  * @param {Number} mode
<span class='line'>936</span>  */</span><span class="WHIT">
<span class='line'>937</span> </span><span class="NAME">GREUtils.quitApplication</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>938</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">Components.interfaces.nsIAppStartup.eAttemptQuit</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>939</span>     </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"app-startup"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">quit</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>940</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>941</span> 
<span class='line'>942</span> 
<span class='line'>943</span> </span><span class="COMM">/**
<span class='line'>944</span>  * Restart Application
<span class='line'>945</span>  *
<span class='line'>946</span>  * see nsIAppStartup
<span class='line'>947</span>  *
<span class='line'>948</span>  * @public
<span class='line'>949</span>  * @static
<span class='line'>950</span>  * @function 
<span class='line'>951</span>  */</span><span class="WHIT">
<span class='line'>952</span> </span><span class="NAME">GREUtils.restartApplication</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>953</span>     </span><span class="NAME">GREUtils.quitApplication</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Components.interfaces.nsIAppStartup.eRestart</span><span class="WHIT"> </span><span class="PUNC">|</span><span class="WHIT"> </span><span class="NAME">Components.interfaces.nsIAppStartup.eAttemptQuit</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>954</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>955</span> 
<span class='line'>956</span> 
<span class='line'>957</span> </span><span class="COMM">/**
<span class='line'>958</span>  * Ram Back  notifyObservers memory-pressure
<span class='line'>959</span>  *
<span class='line'>960</span>  * see memory-pressure
<span class='line'>961</span>  *
<span class='line'>962</span>  * @public
<span class='line'>963</span>  * @static
<span class='line'>964</span>  * @function 
<span class='line'>965</span>  */</span><span class="WHIT">
<span class='line'>966</span> </span><span class="NAME">GREUtils.ramback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>967</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">observerService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"observer-service"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>968</span>     
<span class='line'>969</span>     </span><span class="COMM">// since we don't know the order of how things are going to go, fire these multiple times</span><span class="WHIT">
<span class='line'>970</span>     </span><span class="NAME">observerService.notifyObservers</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"memory-pressure"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"heap-minimize"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>971</span>     </span><span class="NAME">observerService.notifyObservers</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"memory-pressure"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"heap-minimize"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>972</span>     </span><span class="NAME">observerService.notifyObservers</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"memory-pressure"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"heap-minimize"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>973</span> 
<span class='line'>974</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>975</span> 
<span class='line'>976</span>     
<span class='line'>977</span> </span><span class="COMM">/**
<span class='line'>978</span>  * Use Console.logStringMessage(msg);
<span class='line'>979</span>  *
<span class='line'>980</span>  * @public
<span class='line'>981</span>  * @static
<span class='line'>982</span>  * @function
<span class='line'>983</span>  * @param {String} log message 
<span class='line'>984</span>  */</span><span class="WHIT">
<span class='line'>985</span> </span><span class="NAME">GREUtils.log</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sMsg</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>986</span>     </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"consoleservice"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">logStringMessage</span><span class="PUNC">(</span><span class="NAME">sMsg</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>987</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>988</span> 
<span class='line'>989</span> 
<span class='line'>990</span> </span><span class="COMM">/**
<span class='line'>991</span>  * UUID Generator -  use XPCOM base for fast uuid generate.
<span class='line'>992</span>  * 
<span class='line'>993</span>  * @public
<span class='line'>994</span>  * @static
<span class='line'>995</span>  * @function
<span class='line'>996</span>  * @return {String} uuid string 
<span class='line'>997</span>  */</span><span class="WHIT">
<span class='line'>998</span> </span><span class="NAME">GREUtils.uuid</span><span class="WHIT">  </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>999</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">uuid</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/uuid-generator;1"</span><span class="PUNC">,</span><span class="STRN">"nsIUUIDGenerator"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">generateUUID</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">number</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1000</span> 	</span><span class="NAME">uuid</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">uuid.replace</span><span class="PUNC">(</span><span class="REGX">/^{|}$/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">	    
<span class='line'>1001</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">uuid</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1002</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1003</span> 
<span class='line'>1004</span> 
<span class='line'>1005</span> </span><span class="COMM">/**
<span class='line'>1006</span>  * Get Idle Time - 
<span class='line'>1007</span>  * The amount of time in milliseconds that has passed since the last user activity.
<span class='line'>1008</span>  * Firefox3 and XULrunner 1.9 above only.
<span class='line'>1009</span>  * 
<span class='line'>1010</span>  * @public
<span class='line'>1011</span>  * @static
<span class='line'>1012</span>  * @function 
<span class='line'>1013</span>  * @return {Number} idle time
<span class='line'>1014</span>  */</span><span class="WHIT">
<span class='line'>1015</span> </span><span class="NAME">GREUtils.getIdleTime</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1016</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"idleservice"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">idleTime</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1017</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1018</span> 
<span class='line'>1019</span> 
<span class='line'>1020</span> </span><span class="COMM">/**
<span class='line'>1021</span>  * getIdleObserver Helper
<span class='line'>1022</span>  * 
<span class='line'>1023</span>  * call register for Register IdleObserver 
<span class='line'>1024</span>  * call unregister for Remove IdleObserver
<span class='line'>1025</span>  * 
<span class='line'>1026</span>  * Firefox3 and XULrunner 1.9 above only.
<span class='line'>1027</span>  * 
<span class='line'>1028</span>  * @public
<span class='line'>1029</span>  * @static
<span class='line'>1030</span>  * @function 
<span class='line'>1031</span>  * @param {Function} func
<span class='line'>1032</span>  * @param {Integer} time
<span class='line'>1033</span>  * @return {Object} idle Observer Object
<span class='line'>1034</span>  */</span><span class="WHIT">
<span class='line'>1035</span> </span><span class="NAME">GREUtils.getIdleObserver</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">func</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">time</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1036</span> 	
<span class='line'>1037</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">idleObserver</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1038</span> 		</span><span class="NAME">time</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">time</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1039</span> 		
<span class='line'>1040</span>         </span><span class="NAME">observe</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">subject</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">topic</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1041</span> 			</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1042</span> 			 </span><span class="NAME">func</span><span class="PUNC">(</span><span class="NAME">subject</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">topic</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1043</span> 			</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1044</span> 				
<span class='line'>1045</span> 			</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1046</span> 		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1047</span> 		
<span class='line'>1048</span> 		</span><span class="NAME">unregister</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1049</span> 			</span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"idleservice"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">removeIdleObserver</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.time</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1050</span> 		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1051</span> 		
<span class='line'>1052</span> 		</span><span class="NAME">register</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1053</span> 			</span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"idleservice"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">addIdleObserver</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.time</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1054</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1055</span>     </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1056</span> 
<span class='line'>1057</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">idleObserver</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1058</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1059</span> 
<span class='line'>1060</span> 
<span class='line'>1061</span> </span><span class="COMM">/**
<span class='line'>1062</span>  * base-64 encode of a string
<span class='line'>1063</span>  * 
<span class='line'>1064</span>  * @public
<span class='line'>1065</span>  * @static
<span class='line'>1066</span>  * @function 
<span class='line'>1067</span>  * @param {String} str
<span class='line'>1068</span>  * @return {String} base64 string
<span class='line'>1069</span>  */</span><span class="WHIT">
<span class='line'>1070</span> </span><span class="NAME">GREUtils.base64Encode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1071</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">btoa</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1072</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1073</span> 
<span class='line'>1074</span> </span><span class="COMM">/**
<span class='line'>1075</span>  * base-64 decode of a string
<span class='line'>1076</span>  * 
<span class='line'>1077</span>  * @public
<span class='line'>1078</span>  * @static
<span class='line'>1079</span>  * @function 
<span class='line'>1080</span>  * @param {String} str
<span class='line'>1081</span>  * @return {String}
<span class='line'>1082</span>  */</span><span class="WHIT">
<span class='line'>1083</span> </span><span class="NAME">GREUtils.base64Decode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1084</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">atob</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1085</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1086</span> 
<span class='line'>1087</span> </span><span class="COMM">/** 
<span class='line'>1088</span>  * Uppercase the first character of each word in a string
<span class='line'>1089</span>  *
<span class='line'>1090</span>  * @public
<span class='line'>1091</span>  * @static
<span class='line'>1092</span>  * @function 
<span class='line'>1093</span>  * @param {String} word
<span class='line'>1094</span>  * @return {String}
<span class='line'>1095</span>  */</span><span class="WHIT">
<span class='line'>1096</span> </span><span class="NAME">GREUtils.ucwords</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">word</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1097</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">word.replace</span><span class="PUNC">(</span><span class="REGX">/^(.)|\s(.)/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">$1</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">$1.toUpperCase</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1098</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1099</span> 
<span class='line'>1100</span> 
<span class='line'>1101</span> </span><span class="COMM">/**
<span class='line'>1102</span>  * Make a string's first character uppercase
<span class='line'>1103</span>  *
<span class='line'>1104</span>  * @public
<span class='line'>1105</span>  * @static
<span class='line'>1106</span>  * @function 
<span class='line'>1107</span>  * @param {String} word
<span class='line'>1108</span>  * @return {String}
<span class='line'>1109</span>  */</span><span class="WHIT">
<span class='line'>1110</span> </span><span class="NAME">GREUtils.ucfirst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">word</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1111</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">f</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">word.charAt</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toUpperCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1112</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">f</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">word.substr</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">word.length</span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1113</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1114</span> </span><span class="COMM">/**
<span class='line'>1115</span>  * A set of convenience functions for manipulating files.
<span class='line'>1116</span>  *
<span class='line'>1117</span>  * @public
<span class='line'>1118</span>  * @name GREUtils.File
<span class='line'>1119</span>  * @namespace GREUtils.File
<span class='line'>1120</span>  */</span><span class="WHIT">
<span class='line'>1121</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.File'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1122</span> 
<span class='line'>1123</span> </span><span class="NAME">GREUtils.File</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1124</span> 
<span class='line'>1125</span> 	</span><span class="NAME">FILE_RDONLY</span><span class="PUNC">:</span><span class="WHIT">       </span><span class="NUMB">0x01</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1126</span> 	</span><span class="NAME">FILE_WRONLY</span><span class="PUNC">:</span><span class="WHIT">       </span><span class="NUMB">0x02</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1127</span> 	</span><span class="NAME">FILE_RDWR</span><span class="PUNC">:</span><span class="WHIT">         </span><span class="NUMB">0x04</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1128</span> 	</span><span class="NAME">FILE_CREATE_FILE</span><span class="PUNC">:</span><span class="WHIT">  </span><span class="NUMB">0x08</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1129</span> 	</span><span class="NAME">FILE_APPEND</span><span class="PUNC">:</span><span class="WHIT">       </span><span class="NUMB">0x10</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1130</span> 	</span><span class="NAME">FILE_TRUNCATE</span><span class="PUNC">:</span><span class="WHIT">     </span><span class="NUMB">0x20</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1131</span> 	</span><span class="NAME">FILE_SYNC</span><span class="PUNC">:</span><span class="WHIT">         </span><span class="NUMB">0x40</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1132</span> 	</span><span class="NAME">FILE_EXCL</span><span class="PUNC">:</span><span class="WHIT">         </span><span class="NUMB">0x80</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1133</span> 
<span class='line'>1134</span>     </span><span class="NAME">FILE_READ_MODE</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"r"</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1135</span>     </span><span class="NAME">FILE_WRITE_MODE</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"w"</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1136</span>     </span><span class="NAME">FILE_APPEND_MODE</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"a"</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1137</span>     </span><span class="NAME">FILE_BINARY_MODE</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"b"</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1138</span> 
<span class='line'>1139</span>     </span><span class="NAME">NORMAL_FILE_TYPE</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0x00</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1140</span> 	</span><span class="NAME">DIRECTORY_TYPE</span><span class="PUNC">:</span><span class="WHIT">   </span><span class="NUMB">0x01</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1141</span> 
<span class='line'>1142</span>     </span><span class="NAME">FILE_CHUNK</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">1024</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// buffer for readline => set to 1k</span><span class="WHIT">
<span class='line'>1143</span>     </span><span class="NAME">FILE_DEFAULT_PERMS</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0644</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>1144</span> 	</span><span class="NAME">DIR_DEFAULT_PERMS</span><span class="PUNC">:</span><span class="WHIT">  </span><span class="NUMB">0755</span><span class="WHIT">
<span class='line'>1145</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1146</span> 
<span class='line'>1147</span> 
<span class='line'>1148</span> </span><span class="COMM">/**
<span class='line'>1149</span>  * Returns a reference object to a local file location.
<span class='line'>1150</span>  *
<span class='line'>1151</span>  * This method takes a string representing the full file path and returns an nsILocalFile
<span class='line'>1152</span>  * object representing that file location.
<span class='line'>1153</span>  *
<span class='line'>1154</span>  * If "autoCreate" is true then the file is created if it does not already exist.
<span class='line'>1155</span>  *
<span class='line'>1156</span>  * If no file exists at the location or cannot be created (if "autoCreate" is true),
<span class='line'>1157</span>  * null is returned.
<span class='line'>1158</span>  *
<span class='line'>1159</span>  * @public
<span class='line'>1160</span>  * @static
<span class='line'>1161</span>  * @function
<span class='line'>1162</span>  * @param {String} sFile          This is the full path to the file
<span class='line'>1163</span>  * @param {String} autoCreate     This flag indicates whether the file should be created if it does not exist; defaults to false
<span class='line'>1164</span>  * @return                        The file location reference
<span class='line'>1165</span>  * @type                          nsILocalFile
<span class='line'>1166</span>  */</span><span class="WHIT">
<span class='line'>1167</span> </span><span class="NAME">GREUtils.File.getFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sFile</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1168</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">autoCreate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1169</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="REGX">/^file:/</span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">sFile</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1170</span>         </span><span class="NAME">sFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">sFile.replace</span><span class="PUNC">(</span><span class="STRN">"file://"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1171</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">'@mozilla.org/file/local;1'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'nsILocalFile'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1172</span>     </span><span class="NAME">obj.initWithPath</span><span class="PUNC">(</span><span class="NAME">sFile</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1173</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">obj.exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1174</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1175</span>     </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>1176</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">autoCreate</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1177</span>             </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1178</span>                 </span><span class="NAME">obj.create</span><span class="PUNC">(</span><span class="NAME">GREUtils.File.NORMAL_FILE_TYPE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_DEFAULT_PERMS</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1179</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1180</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1181</span>             </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1182</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1183</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1184</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1185</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1186</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1187</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1188</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1189</span> 
<span class='line'>1190</span> 
<span class='line'>1191</span> </span><span class="COMM">/**
<span class='line'>1192</span>  * Constructs an URL reference from an URL string.
<span class='line'>1193</span>  *
<span class='line'>1194</span>  * This method takes a URL string and returns the corresponding URL object. If
<span class='line'>1195</span>  * the URL points to a file resource (i.e. protocol="file:"), this method returns
<span class='line'>1196</span>  * an nsIFileURL. Otherwise an nsIURL is returned.
<span class='line'>1197</span>  *
<span class='line'>1198</span>  * @public
<span class='line'>1199</span>  * @static
<span class='line'>1200</span>  * @function
<span class='line'>1201</span>  * @param {String} sURL           This is the URL string
<span class='line'>1202</span>  * @return                        An URL object
<span class='line'>1203</span>  * @type                          nsIURL|nsIFileURL
<span class='line'>1204</span>  */</span><span class="WHIT">
<span class='line'>1205</span> </span><span class="NAME">GREUtils.File.getURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1206</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1207</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="REGX">/^file:/</span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1208</span>         </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/standard-url;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIURL"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1209</span>         </span><span class="NAME">mURL.spec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">sURL</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1210</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1211</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1212</span>         </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/io-service;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIIOService"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">newURI</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"UTF-8"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1213</span>         </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="PUNC">(</span><span class="NAME">mURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFileURL"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1214</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1215</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">mURL</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1216</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1217</span> 
<span class='line'>1218</span> 
<span class='line'>1219</span> </span><span class="COMM">/**
<span class='line'>1220</span>  * Opens an output stream on a local file.
<span class='line'>1221</span>  *
<span class='line'>1222</span>  * This method opens an output stream on the specified file with the given mode
<span class='line'>1223</span>  * and permission. The file is specified either with a string containing its path, or
<span class='line'>1224</span>  * with a file location reference (nsILocalFile). The file is created with
<span class='line'>1225</span>  * the specified permission if it does not already exist.
<span class='line'>1226</span>  *
<span class='line'>1227</span>  * The mode flag can contain valid combinations of the following:
<span class='line'>1228</span>  *
<span class='line'>1229</span>  *  - "w" (write-only)
<span class='line'>1230</span>  *  - "a" (append)
<span class='line'>1231</span>  *  - "b" (binary)
<span class='line'>1232</span>  *
<span class='line'>1233</span>  * Normally an nsIFileOutputStream object is returned; however, if binary mode ("b") is
<span class='line'>1234</span>  * specified, this method returns an nsIBinaryOutputStream
<span class='line'>1235</span>  * object instead.
<span class='line'>1236</span>  *
<span class='line'>1237</span>  * Returns null if the local file cannot be read or if it cannot be created.
<span class='line'>1238</span>  *
<span class='line'>1239</span>  * @public
<span class='line'>1240</span>  * @static
<span class='line'>1241</span>  * @function
<span class='line'>1242</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1243</span>  * @param {String} mode           This is the mode flag
<span class='line'>1244</span>  * @param {Number} perm           This is the permission with which to create the file (if needed)
<span class='line'>1245</span>  * @return                        A file output stream
<span class='line'>1246</span>  * @type                          nsIFileOutputStream|nsIBinaryOutputStream
<span class='line'>1247</span>  */</span><span class="WHIT">
<span class='line'>1248</span> </span><span class="NAME">GREUtils.File.getOutputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">mode</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">perm</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1249</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.getFile</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1250</span> 
<span class='line'>1251</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">NS_MODE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.FILE_TRUNCATE</span><span class="WHIT"> </span><span class="PUNC">|</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_WRONLY</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1252</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">mode.indexOf</span><span class="PUNC">(</span><span class="STRN">"w"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1253</span>         </span><span class="NAME">NS_MODE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.FILE_TRUNCATE</span><span class="WHIT"> </span><span class="PUNC">|</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_WRONLY</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1254</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">mode.indexOf</span><span class="PUNC">(</span><span class="STRN">"a"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1255</span>         </span><span class="NAME">NS_MODE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.FILE_APPEND</span><span class="WHIT"> </span><span class="PUNC">|</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_RDWR</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1256</span> 
<span class='line'>1257</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsPerm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">perm</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_DEFAULT_PERMS</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1258</span> 
<span class='line'>1259</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1260</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">'@mozilla.org/file/local;1'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'nsILocalFile'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1261</span>         </span><span class="NAME">nsIFile.initWithPath</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1262</span>         </span><span class="NAME">nsIFile.create</span><span class="PUNC">(</span><span class="NAME">GREUtils.File.NORMAL_FILE_TYPE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">nsPerm</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1263</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1264</span> 
<span class='line'>1265</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/file-output-stream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFileOutputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1266</span> 
<span class='line'>1267</span>     </span><span class="NAME">fs.init</span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">NS_MODE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">nsPerm</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1268</span> 
<span class='line'>1269</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">mode.indexOf</span><span class="PUNC">(</span><span class="STRN">"b"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1270</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">binstream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/binaryoutputstream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIBinaryOutputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1271</span>         </span><span class="NAME">binstream.setOutputStream</span><span class="PUNC">(</span><span class="NAME">fs</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1272</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">binstream</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1273</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1274</span>     </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>1275</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1276</span> 
<span class='line'>1277</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1278</span> 
<span class='line'>1279</span> </span><span class="COMM">/**
<span class='line'>1280</span>  * Opens an input stream on a local file.
<span class='line'>1281</span>  *
<span class='line'>1282</span>  * This method opens an input stream on the specified file with the given mode
<span class='line'>1283</span>  * and permission. The file is specified either with a string containing its path, or
<span class='line'>1284</span>  * with a file location reference (nsILocalFile). Null is returned if the file does
<span class='line'>1285</span>  * not already exist.
<span class='line'>1286</span>  *
<span class='line'>1287</span>  * The file is opened in read-only mode.
<span class='line'>1288</span>  *
<span class='line'>1289</span>  * Normally an nsIScriptableInputStream object is returned; however, if binary mode ("b")
<span class='line'>1290</span>  * is specified (through the "mode" parameter), this method returns an nsIBinaryInputStream
<span class='line'>1291</span>  * object instead.
<span class='line'>1292</span>  *
<span class='line'>1293</span>  * @public
<span class='line'>1294</span>  * @static
<span class='line'>1295</span>  * @function
<span class='line'>1296</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1297</span>  * @param {String} mode           This is the mode flag
<span class='line'>1298</span>  * @param {Number} perm           This is the permission with which to create the file (if needed); defaults to FILE_DEFAULT_PERMS
<span class='line'>1299</span>  * @return                        A file output stream
<span class='line'>1300</span>  * @type                          nsIScritableInputStream|nsIBinaryInputStream
<span class='line'>1301</span>  */</span><span class="WHIT">
<span class='line'>1302</span> </span><span class="NAME">GREUtils.File.getInputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">mode</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">perm</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1303</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.getFile</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1304</span> 
<span class='line'>1305</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1306</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1307</span> 
<span class='line'>1308</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">NS_MODE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_RDONLY</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1309</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">mode.indexOf</span><span class="PUNC">(</span><span class="STRN">"r"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1310</span>         </span><span class="NAME">NS_MODE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_RDONLY</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1311</span> 
<span class='line'>1312</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsPerm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">perm</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_DEFAULT_PERMS</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1313</span> 
<span class='line'>1314</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/file-input-stream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFileInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1315</span> 
<span class='line'>1316</span>     </span><span class="NAME">fs.init</span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">NS_MODE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">nsPerm</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1317</span> 
<span class='line'>1318</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">mode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">mode.indexOf</span><span class="PUNC">(</span><span class="STRN">"b"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1319</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">binstream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/binaryinputstream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIBinaryInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1320</span>         </span><span class="NAME">binstream.setInputStream</span><span class="PUNC">(</span><span class="NAME">fs</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1321</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">binstream</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1322</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1323</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1324</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptstream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/scriptableinputstream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIScriptableInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1325</span>         </span><span class="NAME">scriptstream.init</span><span class="PUNC">(</span><span class="NAME">fs</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1326</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">scriptstream</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1327</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1328</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1329</span> 
<span class='line'>1330</span> </span><span class="COMM">/**
<span class='line'>1331</span>  * Opens a line input stream on a local file.
<span class='line'>1332</span>  *
<span class='line'>1333</span>  * This method opens a read-only input stream on the specified file. The file is
<span class='line'>1334</span>  * specified either with a string containing its path, or with a file location
<span class='line'>1335</span>  * reference (nsILocalFile).
<span class='line'>1336</span>  *
<span class='line'>1337</span>  * This method returns an nsILineInputStream, or null if the file cannot be opened
<span class='line'>1338</span>  * for reading.
<span class='line'>1339</span>  *
<span class='line'>1340</span>  * @public
<span class='line'>1341</span>  * @static
<span class='line'>1342</span>  * @function
<span class='line'>1343</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1344</span>  * @return                        A file output stream
<span class='line'>1345</span>  * @type                          nsIScritableInputStream|nsIBinaryInputStream
<span class='line'>1346</span>  */</span><span class="WHIT">
<span class='line'>1347</span> </span><span class="NAME">GREUtils.File.getLineInputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1348</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.getFile</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1349</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1350</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1351</span> 
<span class='line'>1352</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/file-input-stream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFileInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1353</span>     </span><span class="NAME">fs.init</span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_RDONLY</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_DEFAULT_PERMS</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1354</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="PUNC">(</span><span class="NAME">fs</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsILineInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1355</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1356</span> 
<span class='line'>1357</span> </span><span class="COMM">/**
<span class='line'>1358</span>  * Reads in the entire content of a file as a series of lines.
<span class='line'>1359</span>  *
<span class='line'>1360</span>  * This method reads in the specified file on a line-by-line basis, where each line
<span class='line'>1361</span>  * is a possibly zero-length sequence of 8-bit characters terminated by a CR, LF, CRLF,
<span class='line'>1362</span>  * LFCR, or EOF.
<span class='line'>1363</span>  *
<span class='line'>1364</span>  * This method returns the content of the file as an array of lines, with the line
<span class='line'>1365</span>  * terminators stripped out.
<span class='line'>1366</span>  *
<span class='line'>1367</span>  * @public
<span class='line'>1368</span>  * @static
<span class='line'>1369</span>  * @function
<span class='line'>1370</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1371</span>  * @return                        The file content as an array of lines
<span class='line'>1372</span>  * @type                          Array of String
<span class='line'>1373</span>  */</span><span class="WHIT">
<span class='line'>1374</span> </span><span class="NAME">GREUtils.File.readAllLine</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1375</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lineStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getLineInputStream</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1376</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1377</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">buf</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1378</span>         </span><span class="NAME">value</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">""</span><span class="WHIT">
<span class='line'>1379</span>     </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1380</span> 
<span class='line'>1381</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">lineStream</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1382</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1383</span> 
<span class='line'>1384</span>     </span><span class="KEYW">do</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1385</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lineStream.readLine</span><span class="PUNC">(</span><span class="NAME">buf</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1386</span>         </span><span class="NAME">lines.push</span><span class="PUNC">(</span><span class="NAME">buf.value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1387</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1388</span>     </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">rv</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1389</span> 
<span class='line'>1390</span>     </span><span class="NAME">lineStream.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1391</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1392</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1393</span> 
<span class='line'>1394</span> </span><span class="COMM">/**
<span class='line'>1395</span>  * Reads in the entire content of a file as a series of bytes.
<span class='line'>1396</span>  *
<span class='line'>1397</span>  * This method reads in the specified file as a binary stream containing untagged,
<span class='line'>1398</span>  * big-endian binary data.
<span class='line'>1399</span>  *
<span class='line'>1400</span>  * This method returns the content of the file as a String.
<span class='line'>1401</span>  *
<span class='line'>1402</span>  * @public
<span class='line'>1403</span>  * @static
<span class='line'>1404</span>  * @function
<span class='line'>1405</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1406</span>  * @return                        The file content as a String
<span class='line'>1407</span>  * @type                          String
<span class='line'>1408</span>  */</span><span class="WHIT">
<span class='line'>1409</span> </span><span class="NAME">GREUtils.File.readAllBytes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1410</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.getFile</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1411</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">size</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nsIFile.fileSize</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1412</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">binStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getInputStream</span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"rb"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.FILE_DEFAULT_PERMS</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1413</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">binaryString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">binStream.readBytes</span><span class="PUNC">(</span><span class="NAME">size</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1414</span>     </span><span class="NAME">binStream.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1415</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">binaryString</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1416</span> 
<span class='line'>1417</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1418</span> 
<span class='line'>1419</span> </span><span class="COMM">/**
<span class='line'>1420</span>  * Retrieves the content located at an URL.
<span class='line'>1421</span>  *
<span class='line'>1422</span>  * This method retrieves the content located at the given URL, which can reference
<span class='line'>1423</span>  * a remote location. The content is returned as a String. If the URL cannot be
<span class='line'>1424</span>  * retrieved, an empty string is returned.
<span class='line'>1425</span>  *
<span class='line'>1426</span>  * @public
<span class='line'>1427</span>  * @static
<span class='line'>1428</span>  * @function
<span class='line'>1429</span>  * @param {String} aURL           This is the URL from which to retrieve content
<span class='line'>1430</span>  * @return                        The URL content as a String
<span class='line'>1431</span>  * @type                          String
<span class='line'>1432</span>  */</span><span class="WHIT">
<span class='line'>1433</span> </span><span class="NAME">GREUtils.File.getURLContents</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aURL</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1434</span> 
<span class='line'>1435</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">ioService</span><span class="PUNC">=</span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/io-service;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIIOService"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1436</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptableStream</span><span class="PUNC">=</span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/scriptableinputstream;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIScriptableInputStream"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1437</span> 
<span class='line'>1438</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">str</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1439</span> 	</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1440</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">channel</span><span class="PUNC">=</span><span class="NAME">ioService.newChannel</span><span class="PUNC">(</span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1441</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">input</span><span class="PUNC">=</span><span class="NAME">channel.open</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1442</span>       </span><span class="NAME">scriptableStream.init</span><span class="PUNC">(</span><span class="NAME">input</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1443</span> 
<span class='line'>1444</span>       </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">bytes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">input.available</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1445</span> 		</span><span class="NAME">str</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">scriptableStream.read</span><span class="PUNC">(</span><span class="NAME">bytes</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1446</span>       </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1447</span>       </span><span class="NAME">scriptableStream.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1448</span>       </span><span class="NAME">input.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1449</span> 
<span class='line'>1450</span> 	</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1451</span> 
<span class='line'>1452</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1453</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1454</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1455</span> 
<span class='line'>1456</span> </span><span class="COMM">/**
<span class='line'>1457</span>  * Writes an array of strings to a file.
<span class='line'>1458</span>  *
<span class='line'>1459</span>  * This method takes a array of strings and write each string in order to a file.
<span class='line'>1460</span>  * A newline character ('\n') is appended to each string before writing.
<span class='line'>1461</span>  *
<span class='line'>1462</span>  * @public
<span class='line'>1463</span>  * @static
<span class='line'>1464</span>  * @function
<span class='line'>1465</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1466</span>  * @param {Array} lines           This is the Array of Strings to write
<span class='line'>1467</span>  * @return
<span class='line'>1468</span>  * @type                          void
<span class='line'>1469</span>  */</span><span class="WHIT">
<span class='line'>1470</span> </span><span class="NAME">GREUtils.File.writeAllLine</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1471</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">outputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getOutputStream</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"w"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1472</span> 
<span class='line'>1473</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">outputStream</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1474</span>         </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1475</span> 
<span class='line'>1476</span>     </span><span class="NAME">lines.forEach</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">buf</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1477</span>         </span><span class="NAME">buf</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">buf</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1478</span>         </span><span class="NAME">outputStream.write</span><span class="PUNC">(</span><span class="NAME">buf</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"\n"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">buf.length</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1479</span>     </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1480</span> 
<span class='line'>1481</span>     </span><span class="NAME">outputStream.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1482</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1483</span> 
<span class='line'>1484</span> </span><span class="COMM">/**
<span class='line'>1485</span>  * Writes a binary data to a file.
<span class='line'>1486</span>  *
<span class='line'>1487</span>  * @public
<span class='line'>1488</span>  * @static
<span class='line'>1489</span>  * @function
<span class='line'>1490</span>  * @param {Object} file           This is the file. It can be a string containing the file path or a file location reference
<span class='line'>1491</span>  * @param {String} buf            This is the binary data to write
<span class='line'>1492</span>  * @return
<span class='line'>1493</span>  * @type                          void
<span class='line'>1494</span>  */</span><span class="WHIT">
<span class='line'>1495</span> </span><span class="NAME">GREUtils.File.writeAllBytes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">buf</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1496</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">outputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getOutputStream</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"wb"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1497</span> 
<span class='line'>1498</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">outputStream</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1499</span>         </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1500</span> 
<span class='line'>1501</span>     </span><span class="NAME">outputStream.write</span><span class="PUNC">(</span><span class="NAME">buf</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">buf.length</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1502</span> 
<span class='line'>1503</span>     </span><span class="NAME">outputStream.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1504</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1505</span> 
<span class='line'>1506</span> 
<span class='line'>1507</span> </span><span class="COMM">/**
<span class='line'>1508</span>  * Spawns a new process to run an executable file.
<span class='line'>1509</span>  *
<span class='line'>1510</span>  * This method runs an executable file in a newly spawned process. The "aArgs" parameter
<span class='line'>1511</span>  * contains a array of arguments to pass to this executable on its command line. The "blocking"
<span class='line'>1512</span>  * parameter controls whether to block until the process terminates.
<span class='line'>1513</span>  *
<span class='line'>1514</span>  * Normally the process ID of the newly spawn process is returned. A negative return
<span class='line'>1515</span>  * value indicates an error condition:
<span class='line'>1516</span>  *    -1: the file does not exist
<span class='line'>1517</span>  *    -2: the file path points to a directory
<span class='line'>1518</span>  *    -3: other exceptions
<span class='line'>1519</span>  *
<span class='line'>1520</span>  * @public
<span class='line'>1521</span>  * @static
<span class='line'>1522</span>  * @function
<span class='line'>1523</span>  * @param {Object} nsFile         This is the executable file. It can be a string containing the file path or a file location reference
<span class='line'>1524</span>  * @param {String} aArgs          This is the array of arguments to pass to the executable
<span class='line'>1525</span>  * @param {Boolean} blocking      If "true", the method blocks until the process terminates; defaults to false
<span class='line'>1526</span>  * @return {Number}                       The process ID
<span class='line'>1527</span>  * @type                          Int
<span class='line'>1528</span>  */</span><span class="WHIT">
<span class='line'>1529</span> </span><span class="NAME">GREUtils.File.run</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">nsFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArgs</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">blocking</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1530</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">nsFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">this.getFile</span><span class="PUNC">(</span><span class="NAME">nsFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">nsFile</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1531</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1532</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1533</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nsIFile.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1534</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1535</span> 
<span class='line'>1536</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">blocking</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">blocking</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1537</span> 
<span class='line'>1538</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1539</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">process</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/process/util;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIProcess"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1540</span>         </span><span class="COMM">// var process = GREUtils.XPCOM.getService("@mozilla.org/process/util;1", "nsIProcess");</span><span class="WHIT">
<span class='line'>1541</span> 
<span class='line'>1542</span>         </span><span class="NAME">process.init</span><span class="PUNC">(</span><span class="NAME">nsIFile</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1543</span> 
<span class='line'>1544</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1545</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aArgs</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1546</span>             </span><span class="NAME">len</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aArgs.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1547</span>         </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>1548</span>             </span><span class="NAME">aArgs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1549</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">process.run</span><span class="PUNC">(</span><span class="NAME">blocking</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArgs</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1550</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1551</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1552</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.run: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1553</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">3</span><span class="WHIT">
<span class='line'>1554</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1555</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1556</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1557</span> 
<span class='line'>1558</span> </span><span class="COMM">/**
<span class='line'>1559</span>  * Spawns a new process to run an executable file.
<span class='line'>1560</span>  *
<span class='line'>1561</span>  * This method runs an executable file in a newly spawned process. The "aArgs" parameter
<span class='line'>1562</span>  * contains a array of arguments to pass to this executable on its command line. The "blocking"
<span class='line'>1563</span>  * parameter controls whether to block until the process terminates.
<span class='line'>1564</span>  *
<span class='line'>1565</span>  * @public
<span class='line'>1566</span>  * @static
<span class='line'>1567</span>  * @function
<span class='line'>1568</span>  * @param {Object} nsFile         This is the executable file. It can be a string containing the file path or a file location reference
<span class='line'>1569</span>  * @param {String} aArgs          This is the array of arguments to pass to the executable
<span class='line'>1570</span>  * @param {Boolean} blocking      If "true", the method blocks until the process terminates; defaults to false
<span class='line'>1571</span>  * @return
<span class='line'>1572</span>  * @type                          void
<span class='line'>1573</span>  */</span><span class="WHIT">
<span class='line'>1574</span> </span><span class="NAME">GREUtils.File.exec</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1575</span>     </span><span class="NAME">GREUtils.File.run.apply</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1576</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1577</span> 
<span class='line'>1578</span> </span><span class="COMM">/**
<span class='line'>1579</span>  * Resolves a Chrome URL into a loadable URL using information in the Chrome registry.
<span class='line'>1580</span>  * Returns a string representation of the loadable URL if successful; otherwise null
<span class='line'>1581</span>  * is returned.
<span class='line'>1582</span>  *
<span class='line'>1583</span>  * @public
<span class='line'>1584</span>  * @static
<span class='line'>1585</span>  * @function
<span class='line'>1586</span>  * @param {String} chromePath     This is the chrome URL
<span class='line'>1587</span>  * @return {String} url           The loadable URL
<span class='line'>1588</span>  * @type                          String
<span class='line'>1589</span>  */</span><span class="WHIT">
<span class='line'>1590</span> </span><span class="NAME">GREUtils.File.chromeToURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">chromePath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1591</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">uri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getURL</span><span class="PUNC">(</span><span class="NAME">chromePath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1592</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/chrome/chrome-registry;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIChromeRegistry"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1593</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1594</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1595</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cr.convertChromeURL</span><span class="PUNC">(</span><span class="NAME">uri</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1596</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.isString</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1597</span>             </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cr.convertChromeURL</span><span class="PUNC">(</span><span class="NAME">uri</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">spec</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1598</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1599</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1600</span>             </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1601</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1602</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1603</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1604</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.chromeToURL: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1605</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1606</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1607</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1608</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1609</span> 
<span class='line'>1610</span> </span><span class="COMM">/**
<span class='line'>1611</span>  * Resolves a Chrome URL into a file path using information in the Chrome registry.
<span class='line'>1612</span>  * Returns null if resolution fails.
<span class='line'>1613</span>  *
<span class='line'>1614</span>  * @public
<span class='line'>1615</span>  * @static
<span class='line'>1616</span>  * @function
<span class='line'>1617</span>  * @param {String} chromePath     This is the chrome URL
<span class='line'>1618</span>  * @return {String} filepath      The file path
<span class='line'>1619</span>  * @type                          String
<span class='line'>1620</span>  */</span><span class="WHIT">
<span class='line'>1621</span> </span><span class="NAME">GREUtils.File.chromeToPath</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">chromePath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1622</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">uri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getURL</span><span class="PUNC">(</span><span class="NAME">chromePath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1623</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/chrome/chrome-registry;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIChromeRegistry"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1624</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1625</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1626</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cr.convertChromeURL</span><span class="PUNC">(</span><span class="NAME">uri</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1627</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.isString</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1628</span>             </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cr.convertChromeURL</span><span class="PUNC">(</span><span class="NAME">uri</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">spec</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1629</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1630</span> 
<span class='line'>1631</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="REGX">/^file:/</span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1632</span>             </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"file://"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1633</span> 
<span class='line'>1634</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fph</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/network/protocol;1?name=file"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFileProtocolHandler"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1635</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fph.getFileFromURLSpec</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">path</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1636</span> 
<span class='line'>1637</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1638</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1639</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.chromeToPath: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1640</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1641</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1642</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1643</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1644</span> 
<span class='line'>1645</span> 
<span class='line'>1646</span> </span><span class="COMM">/**
<span class='line'>1647</span>  * Checks if a file exists.
<span class='line'>1648</span>  *
<span class='line'>1649</span>  * @public
<span class='line'>1650</span>  * @static
<span class='line'>1651</span>  * @function
<span class='line'>1652</span>  * @param {String} aFile          This is the file path
<span class='line'>1653</span>  * @return {Boolean}              "true" if the file exists; "false" otherwise
<span class='line'>1654</span>  * @type                          Boolean
<span class='line'>1655</span>  */</span><span class="WHIT">
<span class='line'>1656</span> </span><span class="NAME">GREUtils.File.exists</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1657</span> 
<span class='line'>1658</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1659</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1660</span> 
<span class='line'>1661</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1662</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1663</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1664</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1665</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1666</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.exists: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1667</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1668</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1669</span> 
<span class='line'>1670</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1671</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1672</span> 
<span class='line'>1673</span> </span><span class="COMM">/**
<span class='line'>1674</span>  * Removes a file.
<span class='line'>1675</span>  *
<span class='line'>1676</span>  * This method removes a file if it exists. Does not remove directories. Returns
<span class='line'>1677</span>  * "true" if the file is removed, "false" otherwise.
<span class='line'>1678</span>  *
<span class='line'>1679</span>  * @public
<span class='line'>1680</span>  * @static
<span class='line'>1681</span>  * @function
<span class='line'>1682</span>  * @param {String} aFile          This is the file path
<span class='line'>1683</span>  * @return {Boolean}                       "true" if the file exists; "false" otherwise
<span class='line'>1684</span>  * @type                          Boolean
<span class='line'>1685</span>  */</span><span class="WHIT">
<span class='line'>1686</span> </span><span class="NAME">GREUtils.File.remove</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1687</span> 
<span class='line'>1688</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1689</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1690</span> 
<span class='line'>1691</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1692</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1693</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1694</span>         </span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1695</span> 
<span class='line'>1696</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">file.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1697</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1698</span> 
<span class='line'>1699</span>         </span><span class="NAME">file.remove</span><span class="PUNC">(</span><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1700</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1701</span> 
<span class='line'>1702</span> 
<span class='line'>1703</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1704</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1705</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.remove: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1706</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1707</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1708</span> 
<span class='line'>1709</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1710</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1711</span> 
<span class='line'>1712</span> </span><span class="COMM">/**
<span class='line'>1713</span>  * Copies a file to a new location.
<span class='line'>1714</span>  *
<span class='line'>1715</span>  * This method copies an existing file to a new location. If the new location is
<span class='line'>1716</span>  * a directory, that directory must already exist, and the file is copied into that
<span class='line'>1717</span>  * directory with the same file name.
<span class='line'>1718</span>  *
<span class='line'>1719</span>  * This method will not overwrite existing file; if a file already exists at the
<span class='line'>1720</span>  * new location then no copy takes place and the method returns "false".
<span class='line'>1721</span>  *
<span class='line'>1722</span>  * Returns "true" if the file is successfully copied, "false" otherwise.
<span class='line'>1723</span>  *
<span class='line'>1724</span>  * @public
<span class='line'>1725</span>  * @static
<span class='line'>1726</span>  * @function
<span class='line'>1727</span>  * @param {String} aSource        This is the file from which to copy
<span class='line'>1728</span>  * @param {String} aDest          This is the location to which to copy
<span class='line'>1729</span>  * @return {Boolean}              "true" if the copy succeeds; "false" otherwise
<span class='line'>1730</span>  * @type                          Boolean
<span class='line'>1731</span>  */</span><span class="WHIT">
<span class='line'>1732</span> </span><span class="NAME">GREUtils.File.copy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aSource</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aDest</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1733</span> 
<span class='line'>1734</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aSource</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">aDest</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1735</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1736</span> 
<span class='line'>1737</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aSource</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1738</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1739</span> 
<span class='line'>1740</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1741</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1742</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aSource</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1743</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aDest</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1744</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">copyName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.leafName</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1745</span> 
<span class='line'>1746</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fileInst.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1747</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1748</span> 
<span class='line'>1749</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aDest</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">dir.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1750</span>             </span><span class="NAME">copyName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dir.leafName</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1751</span>             </span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">dir.path.replace</span><span class="PUNC">(</span><span class="NAME">copyName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1752</span> 
<span class='line'>1753</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">dir.path</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1754</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1755</span> 
<span class='line'>1756</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dir.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1757</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1758</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1759</span> 
<span class='line'>1760</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">GREUtils.File.append</span><span class="PUNC">(</span><span class="NAME">dir.path</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">copyName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1761</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1762</span> 
<span class='line'>1763</span>         </span><span class="NAME">fileInst.copyTo</span><span class="PUNC">(</span><span class="NAME">dir</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">copyName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1764</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1765</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1766</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1767</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.copy: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1768</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1769</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1770</span> 
<span class='line'>1771</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1772</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1773</span> 
<span class='line'>1774</span>  </span><span class="COMM">/**
<span class='line'>1775</span>  * Creates a new file path by appending a file name to a directory path and returns
<span class='line'>1776</span>  * that new file path.  Returns an empty string if the directory does not exist or
<span class='line'>1777</span>  * if the directory path given does not point to an actual directory.
<span class='line'>1778</span>  *
<span class='line'>1779</span>  * @public
<span class='line'>1780</span>  * @static
<span class='line'>1781</span>  * @function
<span class='line'>1782</span>  * @param {String} aDirPath       This is the directory path
<span class='line'>1783</span>  * @param {String} aFileName      This is the file name to append to the directory
<span class='line'>1784</span>  * @return {String} filePath      The new file path, empty String if error
<span class='line'>1785</span>  * @type                          String
<span class='line'>1786</span>  */</span><span class="WHIT">
<span class='line'>1787</span> </span><span class="NAME">GREUtils.File.append</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aDirPath</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aFileName</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1788</span> 
<span class='line'>1789</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aDirPath</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">aFileName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1790</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1791</span> 
<span class='line'>1792</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aDirPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1793</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1794</span> 
<span class='line'>1795</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1796</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1797</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aDirPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1798</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fileInst.exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">fileInst.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1799</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1800</span> 
<span class='line'>1801</span>         </span><span class="NAME">fileInst.append</span><span class="PUNC">(</span><span class="NAME">aFileName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1802</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.path</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1803</span>         </span><span class="KEYW">delete</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1804</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1805</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1806</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.append: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1807</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1808</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1809</span> 
<span class='line'>1810</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1811</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1812</span> 
<span class='line'>1813</span> 
<span class='line'>1814</span> </span><span class="COMM">/**
<span class='line'>1815</span>  * Returns the Unix style permission bits of a file or directory. Returns 0 if the
<span class='line'>1816</span>  * file or directory does not exist.
<span class='line'>1817</span>  *
<span class='line'>1818</span>  * @public
<span class='line'>1819</span>  * @static
<span class='line'>1820</span>  * @function
<span class='line'>1821</span>  * @param {String} aPath          This is the file path
<span class='line'>1822</span>  * @return {String}               The octal representation of the Unix style permission bits
<span class='line'>1823</span>  * @type                          String
<span class='line'>1824</span>  */</span><span class="WHIT">
<span class='line'>1825</span> </span><span class="NAME">GREUtils.File.permissions</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1826</span> 
<span class='line'>1827</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1828</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1829</span> 
<span class='line'>1830</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1831</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1832</span> 
<span class='line'>1833</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1834</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1835</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">permissions.toString</span><span class="PUNC">(</span><span class="NUMB">8</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1836</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1837</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1838</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.permissions: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1839</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1840</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1841</span> 
<span class='line'>1842</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1843</span> 
<span class='line'>1844</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1845</span> 
<span class='line'>1846</span> </span><span class="COMM">/**
<span class='line'>1847</span>  * Returns the modification date of a file or directory. Returns 0 if the file or
<span class='line'>1848</span>  * directory does not exist.
<span class='line'>1849</span>  *
<span class='line'>1850</span>  * @public
<span class='line'>1851</span>  * @static
<span class='line'>1852</span>  * @function
<span class='line'>1853</span>  * @param {String} aPath          This is the file path
<span class='line'>1854</span>  * @return {Date}                 The modification date
<span class='line'>1855</span>  * @type                          String
<span class='line'>1856</span>  */</span><span class="WHIT">
<span class='line'>1857</span> </span><span class="NAME">GREUtils.File.dateModified</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1858</span> 
<span class='line'>1859</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1860</span> 
<span class='line'>1861</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">this.exists</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1862</span> 
<span class='line'>1863</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1864</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1865</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">lastModifiedTime</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toLocaleString</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1866</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1867</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1868</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.dateModified: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1869</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1870</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1871</span> 
<span class='line'>1872</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1873</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1874</span> 
<span class='line'>1875</span> </span><span class="COMM">/**
<span class='line'>1876</span>  * Returns the size of a file. Returns -1 if the file does not exist or if the
<span class='line'>1877</span>  * file size cannot be determined.
<span class='line'>1878</span>  *
<span class='line'>1879</span>  * @public
<span class='line'>1880</span>  * @static
<span class='line'>1881</span>  * @function
<span class='line'>1882</span>  * @param {String} aPath          This is the file path
<span class='line'>1883</span>  * @return {Number}               The file size
<span class='line'>1884</span>  * @type                          Int
<span class='line'>1885</span>  */</span><span class="WHIT">
<span class='line'>1886</span> </span><span class="NAME">GREUtils.File.size</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1887</span> 
<span class='line'>1888</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1889</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1890</span> 
<span class='line'>1891</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1892</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1893</span> 
<span class='line'>1894</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1895</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1896</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">fileSize</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1897</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1898</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1899</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.size: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1900</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1901</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1902</span> 
<span class='line'>1903</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1904</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1905</span> 
<span class='line'>1906</span> </span><span class="COMM">/**
<span class='line'>1907</span>  * Returns the extension of a file. Returns an empty string if the file does not exist
<span class='line'>1908</span>  * or if the file extension cannot be determined.
<span class='line'>1909</span>  *
<span class='line'>1910</span>  * @public
<span class='line'>1911</span>  * @static
<span class='line'>1912</span>  * @function
<span class='line'>1913</span>  * @param {String} aPath          This is the file path
<span class='line'>1914</span>  * @return {String} filePath      The file extension, empty String if error.
<span class='line'>1915</span>  * @type                          String
<span class='line'>1916</span>  */</span><span class="WHIT">
<span class='line'>1917</span> </span><span class="NAME">GREUtils.File.ext</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1918</span> 
<span class='line'>1919</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1920</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1921</span> 
<span class='line'>1922</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">GREUtils.File.exists</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1923</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1924</span> 
<span class='line'>1925</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1926</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1927</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">leafName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">leafName</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1928</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dotIndex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">leafName.lastIndexOf</span><span class="PUNC">(</span><span class="STRN">'.'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1929</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">dotIndex</span><span class="WHIT"> </span><span class="PUNC">>=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">leafName.substring</span><span class="PUNC">(</span><span class="NAME">dotIndex</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1930</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1931</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1932</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.ext: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1933</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="WHIT">
<span class='line'>1934</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1935</span> 
<span class='line'>1936</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1937</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1938</span> 
<span class='line'>1939</span> </span><span class="COMM">/**
<span class='line'>1940</span>  * Returns the parent path of a file path.
<span class='line'>1941</span>  *
<span class='line'>1942</span>  * If "aPath" is a file, this method returns the path of the directory containing the
<span class='line'>1943</span>  * file. If "aPath" is a directory, this method returns the path of the directory itself.
<span class='line'>1944</span>  *
<span class='line'>1945</span>  * Returns an empty string if "aPath" does not exist.
<span class='line'>1946</span>  *
<span class='line'>1947</span>  * @public
<span class='line'>1948</span>  * @static
<span class='line'>1949</span>  * @function
<span class='line'>1950</span>  * @param {String} aPath          This is the file path
<span class='line'>1951</span>  * @return {String} filePath      The parent path, empty String if error
<span class='line'>1952</span>  * @type                          String
<span class='line'>1953</span>  */</span><span class="WHIT">
<span class='line'>1954</span> </span><span class="NAME">GREUtils.File.parent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1955</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1956</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1957</span> 
<span class='line'>1958</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1959</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1960</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1961</span> 
<span class='line'>1962</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">fileInst.exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1963</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1964</span> 
<span class='line'>1965</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fileInst.isFile</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1966</span>             </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.parent.path</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1967</span> 
<span class='line'>1968</span>         </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>1969</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fileInst.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>1970</span>                 </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.path</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1971</span> 
<span class='line'>1972</span>             </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>1973</span>                 </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1974</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1975</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1976</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.parent: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1977</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1978</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>1979</span> 
<span class='line'>1980</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1981</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1982</span> 
<span class='line'>1983</span> 
<span class='line'>1984</span> </span><span class="COMM">/**
<span class='line'>1985</span>  * Checks if a file path points to a regular file.
<span class='line'>1986</span>  *
<span class='line'>1987</span>  * @public
<span class='line'>1988</span>  * @static
<span class='line'>1989</span>  * @function
<span class='line'>1990</span>  * @param {String} aPath          This is the file path
<span class='line'>1991</span>  * @return {Boolean}              "true" if the path is a file; "false" otherwise
<span class='line'>1992</span>  * @type                          Boolean
<span class='line'>1993</span>  */</span><span class="WHIT">
<span class='line'>1994</span> </span><span class="NAME">GREUtils.File.isDir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1995</span> 
<span class='line'>1996</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1997</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>1998</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>1999</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2000</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2001</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2002</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isDir: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2003</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2004</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2005</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2006</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2007</span> 
<span class='line'>2008</span> </span><span class="COMM">/**
<span class='line'>2009</span>  * Checks if a file path points to a regular file.
<span class='line'>2010</span>  *
<span class='line'>2011</span>  * @public
<span class='line'>2012</span>  * @static
<span class='line'>2013</span>  * @function
<span class='line'>2014</span>  * @param {String} aPath          This is the file path
<span class='line'>2015</span>  * @return {Boolean}              "true" if the path is a file; "false" otherwise
<span class='line'>2016</span>  * @type                          Boolean
<span class='line'>2017</span>  */</span><span class="WHIT">
<span class='line'>2018</span> </span><span class="NAME">GREUtils.File.isFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2019</span> 
<span class='line'>2020</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2021</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2022</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2023</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isFile</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2024</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2025</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2026</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isFile: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2027</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2028</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2029</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2030</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2031</span> 
<span class='line'>2032</span> </span><span class="COMM">/**
<span class='line'>2033</span>  * Checks if a file is executable.
<span class='line'>2034</span>  *
<span class='line'>2035</span>  * @public
<span class='line'>2036</span>  * @static
<span class='line'>2037</span>  * @function
<span class='line'>2038</span>  * @param {String} aPath          This is the file
<span class='line'>2039</span>  * @return {Boolean}              "true" if the path is an executable file; "false" otherwise
<span class='line'>2040</span>  * @type                          Boolean
<span class='line'>2041</span>  */</span><span class="WHIT">
<span class='line'>2042</span> </span><span class="NAME">GREUtils.File.isExecutable</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2043</span> 
<span class='line'>2044</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2045</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2046</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2047</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isExecutable</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2048</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2049</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2050</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isExecutable: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2051</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2052</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2053</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2054</span> 
<span class='line'>2055</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2056</span> 
<span class='line'>2057</span> 
<span class='line'>2058</span> </span><span class="COMM">/**
<span class='line'>2059</span>  * Checks if a file path points to a symbolic link.
<span class='line'>2060</span>  *
<span class='line'>2061</span>  * @public
<span class='line'>2062</span>  * @static
<span class='line'>2063</span>  * @function
<span class='line'>2064</span>  * @param {String} aPath          This is the file path
<span class='line'>2065</span>  * @return {Boolean}              "true" if the path is a symbolic link; "false" otherwise
<span class='line'>2066</span>  * @type                          Boolean
<span class='line'>2067</span>  */</span><span class="WHIT">
<span class='line'>2068</span> </span><span class="NAME">GREUtils.File.isSymlink</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2069</span> 
<span class='line'>2070</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2071</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2072</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2073</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isSymlink</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2074</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2075</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2076</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isSymlink: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2077</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2078</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2079</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2080</span> 
<span class='line'>2081</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2082</span> 
<span class='line'>2083</span> </span><span class="COMM">/**
<span class='line'>2084</span>  * Checks if a file or directory is writable by the user.
<span class='line'>2085</span>  *
<span class='line'>2086</span>  * @public
<span class='line'>2087</span>  * @static
<span class='line'>2088</span>  * @function
<span class='line'>2089</span>  * @param {String} aPath          This is the file or directory
<span class='line'>2090</span>  * @return {Boolean}              "true" if the path is writable; "false" otherwise
<span class='line'>2091</span>  * @type                          Boolean
<span class='line'>2092</span>  */</span><span class="WHIT">
<span class='line'>2093</span> </span><span class="NAME">GREUtils.File.isWritable</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2094</span> 
<span class='line'>2095</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2096</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2097</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2098</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isWritable</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2099</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2100</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2101</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isWritable: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2102</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2103</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2104</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2105</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2106</span> 
<span class='line'>2107</span> </span><span class="COMM">/**
<span class='line'>2108</span>  * Checks if a file or directory is hidden.
<span class='line'>2109</span>  *
<span class='line'>2110</span>  * @public
<span class='line'>2111</span>  * @static
<span class='line'>2112</span>  * @function
<span class='line'>2113</span>  * @param {String} aPath          This is the file or directory
<span class='line'>2114</span>  * @return {Boolean}              "true" if the path is writable; "false" otherwise
<span class='line'>2115</span>  * @type                          Boolean
<span class='line'>2116</span>  */</span><span class="WHIT">
<span class='line'>2117</span> </span><span class="NAME">GREUtils.File.isHidden</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2118</span> 
<span class='line'>2119</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2120</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2121</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2122</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isHidden</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2123</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2124</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2125</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isHidden: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2126</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2127</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2128</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2129</span> 
<span class='line'>2130</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2131</span> 
<span class='line'>2132</span> </span><span class="COMM">/**
<span class='line'>2133</span>  * Checks if a file path points to a special system file.
<span class='line'>2134</span>  *
<span class='line'>2135</span>  * @public
<span class='line'>2136</span>  * @static
<span class='line'>2137</span>  * @function
<span class='line'>2138</span>  * @param {String} aPath          This is the file path
<span class='line'>2139</span>  * @return {Boolean}              "true" if the file is special; "false" otherwise
<span class='line'>2140</span>  * @type                          Boolean
<span class='line'>2141</span>  */</span><span class="WHIT">
<span class='line'>2142</span> </span><span class="NAME">GREUtils.File.isSpecial</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2143</span> 
<span class='line'>2144</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2145</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2146</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2147</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.isSpecial</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2148</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2149</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2150</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.isSpecial: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2151</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2152</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2153</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2154</span> 
<span class='line'>2155</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2156</span> 
<span class='line'>2157</span> </span><span class="COMM">/**
<span class='line'>2158</span>  * Returns the canonical file path.
<span class='line'>2159</span>  *
<span class='line'>2160</span>  * Returns -1 if the file path does not exist or if read permission is denied for a
<span class='line'>2161</span>  * component of the path prefix.
<span class='line'>2162</span>  *
<span class='line'>2163</span>  * @public
<span class='line'>2164</span>  * @static
<span class='line'>2165</span>  * @function
<span class='line'>2166</span>  * @param {String} aPath          This is the file path to normalize
<span class='line'>2167</span>  * @return                        The normalized file path
<span class='line'>2168</span>  * @type                          String
<span class='line'>2169</span>  */</span><span class="WHIT">
<span class='line'>2170</span> </span><span class="NAME">GREUtils.File.normalize</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2171</span> 
<span class='line'>2172</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2173</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2174</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2175</span> 		</span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.normalize</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2176</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2177</span>     </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2178</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.File.normalize: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2179</span>         </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2180</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2181</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2182</span> 
<span class='line'>2183</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2184</span> </span><span class="COMM">/**
<span class='line'>2185</span>  * A set of utility functions that provide various directory operations on the
<span class='line'>2186</span>  * local file system in a platform-independent manner.
<span class='line'>2187</span>  *
<span class='line'>2188</span>  * @public
<span class='line'>2189</span>  * @name GREUtils.Dir
<span class='line'>2190</span>  * @namespace GREUtils.Dir
<span class='line'>2191</span>  */</span><span class="WHIT">
<span class='line'>2192</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Dir'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2193</span> 
<span class='line'>2194</span> 
<span class='line'>2195</span> </span><span class="COMM">/**
<span class='line'>2196</span>  * Returns a nsILocalFile instsance representing the given file.
<span class='line'>2197</span>  *
<span class='line'>2198</span>  * Bt setting autoCreate to "true", this method will attempt to create the file
<span class='line'>2199</span>  * with default permissions if the file does not already exists.
<span class='line'>2200</span>  *
<span class='line'>2201</span>  * If the file does not exist and is not/cannot be created, null will be returned.
<span class='line'>2202</span>  *
<span class='line'>2203</span>  * @public
<span class='line'>2204</span>  * @static
<span class='line'>2205</span>  * @function
<span class='line'>2206</span>  * @param {String} aPath                This is the file path
<span class='line'>2207</span>  * @param {Boolean} autoCreate          This flag indicates whether to create the file if it does not exist; false by default
<span class='line'>2208</span>  * @return {nsILocalFile}               The file, or null if the file does not exist and is not/cannot be created
<span class='line'>2209</span>  * @type                                nsILocalFile
<span class='line'>2210</span>  */</span><span class="WHIT">
<span class='line'>2211</span> </span><span class="NAME">GREUtils.Dir.getFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2212</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">autoCreate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2213</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="REGX">/^file:/</span><span class="PUNC">.</span><span class="NAME">test</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2214</span>         </span><span class="NAME">aPath</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aPath.replace</span><span class="PUNC">(</span><span class="STRN">"file://"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2215</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.createInstance</span><span class="PUNC">(</span><span class="STRN">'@mozilla.org/file/local;1'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'nsILocalFile'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2216</span>     </span><span class="NAME">obj.initWithPath</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2217</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">obj.exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2218</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2219</span>     </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>2220</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">autoCreate</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2221</span>             </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2222</span>                 </span><span class="NAME">obj.create</span><span class="PUNC">(</span><span class="NAME">GREUtils.File.DIRECTORY_TYPE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.DIR_DEFAULT_PERMS</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2223</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">obj</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2224</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2225</span>             </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2226</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2227</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2228</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2229</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2230</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2231</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2232</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2233</span> 
<span class='line'>2234</span> 
<span class='line'>2235</span> </span><span class="COMM">/**
<span class='line'>2236</span>  * Creates a new file at the given path with default permissions and returns
<span class='line'>2237</span>  * an nsILocalFile instance representing the file.
<span class='line'>2238</span>  *
<span class='line'>2239</span>  * If the file already exists, that file is returned. If the file cannot be created,
<span class='line'>2240</span>  * null is returned.
<span class='line'>2241</span>  *
<span class='line'>2242</span>  * @public
<span class='line'>2243</span>  * @static
<span class='line'>2244</span>  * @function
<span class='line'>2245</span>  * @param {String} aPath                This is the file path
<span class='line'>2246</span>  * @return {nsILocalFile}               The file, or null if the file does not exist and is not/cannot be created
<span class='line'>2247</span>  * @type                                nsILocalFile
<span class='line'>2248</span>  */</span><span class="WHIT">
<span class='line'>2249</span> </span><span class="NAME">GREUtils.Dir.create</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2250</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dir.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2251</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2252</span> 
<span class='line'>2253</span> 
<span class='line'>2254</span> </span><span class="COMM">/**
<span class='line'>2255</span>  * Removes a directory.
<span class='line'>2256</span>  *
<span class='line'>2257</span>  * If aRecursive is false, then the directory must be empty before it can be deleted.
<span class='line'>2258</span>  *
<span class='line'>2259</span>  * @public
<span class='line'>2260</span>  * @static
<span class='line'>2261</span>  * @function
<span class='line'>2262</span>  * @param {String} aPath                This is the directory path
<span class='line'>2263</span>  * @param {Boolean} aRecursive          This flag indicates if directory is to be deleted if it is not empty
<span class='line'>2264</span>  * @return {Number}                     void  : directory is successfully removed
<span class='line'>2265</span>  *                                      -1    : path does not exist
<span class='line'>2266</span>  *                                      -2    : aPath is not a directory
<span class='line'>2267</span>  *                                      -3    : delete fails
<span class='line'>2268</span>  * @type                                Int
<span class='line'>2269</span>  */</span><span class="WHIT">
<span class='line'>2270</span> </span><span class="NAME">GREUtils.Dir.remove</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aRecursive</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2271</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dir.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2272</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2273</span> 
<span class='line'>2274</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dir.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2275</span> 
<span class='line'>2276</span> 	</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2277</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dir.remove</span><span class="PUNC">(</span><span class="NAME">aRecursive</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2278</span> 	</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2279</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.Dir.remove: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2280</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">3</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2281</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2282</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2283</span> 
<span class='line'>2284</span> 
<span class='line'>2285</span> </span><span class="COMM">/**
<span class='line'>2286</span>  * Tests whether a file is a descendant of a directory.
<span class='line'>2287</span>  *
<span class='line'>2288</span>  * This method will also return false if either file or the directory does not exist.
<span class='line'>2289</span>  *
<span class='line'>2290</span>  * @public
<span class='line'>2291</span>  * @static
<span class='line'>2292</span>  * @function
<span class='line'>2293</span>  * @param {String} aPath                This is the directory to test
<span class='line'>2294</span>  * @param {String} aFile                This is the full path of the file to test
<span class='line'>2295</span>  * @return {Boolean}                    Returns true if the file is a descendant of the directory, false otherwise
<span class='line'>2296</span>  * @type                                Boolean
<span class='line'>2297</span>  */</span><span class="WHIT">
<span class='line'>2298</span> </span><span class="NAME">GREUtils.Dir.contains</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2299</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dir.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2300</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2301</span> 
<span class='line'>2302</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">dir</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2303</span> 
<span class='line'>2304</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dir.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2305</span> 	
<span class='line'>2306</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dir.isFile</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2307</span> 
<span class='line'>2308</span> 	</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2309</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dir.contains</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2310</span> 	</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2311</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.Dir.contains: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2312</span> 		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2313</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2314</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2315</span> 
<span class='line'>2316</span> 
<span class='line'>2317</span> </span><span class="COMM">/**
<span class='line'>2318</span>  * Reads directory entries.
<span class='line'>2319</span>  *
<span class='line'>2320</span>  * This method returns the directory entries as an array. Each array
<span class='line'>2321</span>  * element can be a string representing a file path, or an array of representing
<span class='line'>2322</span>  * a sub-directory.
<span class='line'>2323</span>  *
<span class='line'>2324</span>  * If the given path is not a directory an empty array is returned.
<span class='line'>2325</span>  *
<span class='line'>2326</span>  * @public
<span class='line'>2327</span>  * @static
<span class='line'>2328</span>  * @function
<span class='line'>2329</span>  * @param {String} aPath                This is the directory path
<span class='line'>2330</span>  * @return {Object}                     Returns the directory entries as an array of strings containing file paths
<span class='line'>2331</span>  * @type                                Object
<span class='line'>2332</span>  */</span><span class="WHIT">
<span class='line'>2333</span> </span><span class="NAME">GREUtils.Dir.readDir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2334</span> 
<span class='line'>2335</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dir.getFile</span><span class="PUNC">(</span><span class="NAME">aPath</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2336</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2337</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fileInst</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2338</span> 
<span class='line'>2339</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2340</span> 
<span class='line'>2341</span> 	  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">fileInst.exists</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2342</span> 
<span class='line'>2343</span>       </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">fileInst.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2344</span> 
<span class='line'>2345</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">files</span><span class="WHIT">     </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">fileInst.directoryEntries</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2346</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">file</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2347</span> 
<span class='line'>2348</span>       </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">files.hasMoreElements</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2349</span>       </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2350</span>         </span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">files.getNext</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2351</span> 		</span><span class="NAME">file</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="PUNC">(</span><span class="NAME">file</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsILocalFile"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2352</span> 
<span class='line'>2353</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">file.isFile</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">rv.push</span><span class="PUNC">(</span><span class="NAME">file.path</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2354</span> 
<span class='line'>2355</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">file.isDirectory</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2356</span>           </span><span class="NAME">rv.push</span><span class="PUNC">(</span><span class="NAME">GREUtils.Dir.readDir</span><span class="PUNC">(</span><span class="NAME">file.path</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2357</span>       </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2358</span> 
<span class='line'>2359</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2360</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.Dir.readDir: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2361</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2362</span> 
<span class='line'>2363</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rv</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2364</span> 
<span class='line'>2365</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2366</span> </span><span class="COMM">/**
<span class='line'>2367</span>  * A Javascript wrapper around the XPCOM nsiCryptoHash component that provides
<span class='line'>2368</span>  * native implementation of cryptographic hash function. This can be used,
<span class='line'>2369</span>  * for example, to calculate the MD5 hash of a file to determine if it contains
<span class='line'>2370</span>  * the data you think it does.
<span class='line'>2371</span>  *
<span class='line'>2372</span>  * The hash algorithms supported are MD2, MD5, SHA-1, SHA-256, SHA-384, and SHA-512.
<span class='line'>2373</span>  *
<span class='line'>2374</span>  * @public
<span class='line'>2375</span>  * @name GREUtils.CryptoHash
<span class='line'>2376</span>  * @namespace GREUtils.CryptoHash
<span class='line'>2377</span>  */</span><span class="WHIT">
<span class='line'>2378</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.CryptoHash'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2379</span> 
<span class='line'>2380</span> 
<span class='line'>2381</span> </span><span class="COMM">/**
<span class='line'>2382</span>  * Computes the hash of a string.
<span class='line'>2383</span>  *
<span class='line'>2384</span>  * This method takes a UTF-8 string and computes its hash using the specified
<span class='line'>2385</span>  * algorithm.
<span class='line'>2386</span>  *
<span class='line'>2387</span>  * @public
<span class='line'>2388</span>  * @static
<span class='line'>2389</span>  * @function
<span class='line'>2390</span>  * @param {String} str          This is the UTF-8 string to compute the hash for
<span class='line'>2391</span>  * @param {String} algorithm    This is the hash algorithm to use
<span class='line'>2392</span>  * @return {String} string      The resulting hash as a hex string
<span class='line'>2393</span>  * @type                        String
<span class='line'>2394</span>  */</span><span class="WHIT">
<span class='line'>2395</span> </span><span class="NAME">GREUtils.CryptoHash.crypt</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">algorithm</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2396</span> 
<span class='line'>2397</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">converter</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">	</span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">'unicodeconverter'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2398</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cryptohash</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">'hash'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2399</span> 
<span class='line'>2400</span> 	</span><span class="NAME">converter.charset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"UTF-8"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2401</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2402</span> 	</span><span class="COMM">// data is an array of bytes</span><span class="WHIT">
<span class='line'>2403</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">converter.convertToByteArray</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2404</span> 
<span class='line'>2405</span> 	</span><span class="COMM">// init algorithm</span><span class="WHIT">
<span class='line'>2406</span> 	</span><span class="NAME">cryptohash.init</span><span class="PUNC">(</span><span class="NAME">cryptohash</span><span class="PUNC">[</span><span class="NAME">algorithm</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2407</span> 
<span class='line'>2408</span> 	</span><span class="NAME">cryptohash.update</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data.length</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2409</span> 
<span class='line'>2410</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hash</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cryptohash.finish</span><span class="PUNC">(</span><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2411</span> 
<span class='line'>2412</span> 	</span><span class="COMM">// convert the binary hash data to a hex string.</span><span class="WHIT">
<span class='line'>2413</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.arrayToHexString</span><span class="PUNC">(</span><span class="NAME">hash</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2414</span> 
<span class='line'>2415</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2416</span> 
<span class='line'>2417</span> </span><span class="COMM">/**
<span class='line'>2418</span>  * Computes the hash of a file.
<span class='line'>2419</span>  *
<span class='line'>2420</span>  * This method reads data from a file and computes its hash using the specified
<span class='line'>2421</span>  * algorithm. The file can be specified as a string containing the file path or
<span class='line'>2422</span>  * as an nsIFile object.
<span class='line'>2423</span>  *
<span class='line'>2424</span>  * @public
<span class='line'>2425</span>  * @static
<span class='line'>2426</span>  * @function
<span class='line'>2427</span>  * @param {String|nsIFile} file   This is the file given as a file path or an nsIFile object
<span class='line'>2428</span>  * @param {String} algorithm      This is the hash algorithm to use
<span class='line'>2429</span>  * @return {String}               The resulting hash as a hex string; an empty string is returned if the file is empty or cannot be read
<span class='line'>2430</span>  * @type                          String
<span class='line'>2431</span>  */</span><span class="WHIT">
<span class='line'>2432</span> </span><span class="NAME">GREUtils.CryptoHash.cryptFromStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">algorithm</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2433</span> 
<span class='line'>2434</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cryptohash</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">'hash'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2435</span> 
<span class='line'>2436</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">istream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getInputStream</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2437</span> 
<span class='line'>2438</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">GREUtils.isNull</span><span class="PUNC">(</span><span class="NAME">istream</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2439</span> 
<span class='line'>2440</span> 	</span><span class="COMM">// init algorithm</span><span class="WHIT">
<span class='line'>2441</span> 	</span><span class="NAME">cryptohash.init</span><span class="PUNC">(</span><span class="NAME">cryptohash</span><span class="PUNC">[</span><span class="NAME">algorithm</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2442</span> 
<span class='line'>2443</span> 	</span><span class="COMM">// this tells updateFromStream to read the entire file</span><span class="WHIT">
<span class='line'>2444</span> 	</span><span class="KEYW">const</span><span class="WHIT"> </span><span class="NAME">PR_UINT32_MAX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0xffffffff</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2445</span> 	</span><span class="NAME">cryptohash.updateFromStream</span><span class="PUNC">(</span><span class="NAME">istream</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">PR_UINT32_MAX</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2446</span> 
<span class='line'>2447</span> 	</span><span class="COMM">// pass false here to get binary data back</span><span class="WHIT">
<span class='line'>2448</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">hash</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cryptohash.finish</span><span class="PUNC">(</span><span class="KEYW">false</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2449</span> 
<span class='line'>2450</span> 	</span><span class="COMM">// convert the binary hash data to a hex string.</span><span class="WHIT">
<span class='line'>2451</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.arrayToHexString</span><span class="PUNC">(</span><span class="NAME">hash</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2452</span> 
<span class='line'>2453</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2454</span> 
<span class='line'>2455</span> 
<span class='line'>2456</span> </span><span class="COMM">/**
<span class='line'>2457</span>  * Computes the MD5 hash of a string.
<span class='line'>2458</span>  *
<span class='line'>2459</span>  * This method takes a UTF-8 string and computes its hash using the MD5 algorithm.
<span class='line'>2460</span>  *
<span class='line'>2461</span>  * @public
<span class='line'>2462</span>  * @static
<span class='line'>2463</span>  * @function
<span class='line'>2464</span>  * @param {String} str              This is the UTF-8 string to compute the hash for
<span class='line'>2465</span>  * @return {String}                 The resulting hash as a hex string
<span class='line'>2466</span>  * @type                            String
<span class='line'>2467</span>  */</span><span class="WHIT">
<span class='line'>2468</span> </span><span class="NAME">GREUtils.CryptoHash.md5</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2469</span> 
<span class='line'>2470</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.crypt</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"MD5"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2471</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2472</span> 
<span class='line'>2473</span> </span><span class="COMM">/**
<span class='line'>2474</span>  * Computes the MD5 hash of a file.
<span class='line'>2475</span>  *
<span class='line'>2476</span>  * This method reads data from a file and computes its hash using the MD5
<span class='line'>2477</span>  * algorithm. The file can be specified as a string containing the file path or
<span class='line'>2478</span>  * as an nsIFile object.
<span class='line'>2479</span>  *
<span class='line'>2480</span>  * @public
<span class='line'>2481</span>  * @static
<span class='line'>2482</span>  * @function
<span class='line'>2483</span>  * @param {String|nsIFile} aFile  This is the file given as a file path or an nsIFile object
<span class='line'>2484</span>  * @return {String}               The resulting hash as a hex string; an empty string is returned if the file is empty or cannot be read
<span class='line'>2485</span>  * @type                          String
<span class='line'>2486</span>  */</span><span class="WHIT">
<span class='line'>2487</span> </span><span class="NAME">GREUtils.CryptoHash.md5FromFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2488</span> 
<span class='line'>2489</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.cryptFromStream</span><span class="PUNC">(</span><span class="NAME">aFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"MD5"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2490</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2491</span> 
<span class='line'>2492</span> </span><span class="COMM">/**
<span class='line'>2493</span>  * Computes the MD5 hash of a file.
<span class='line'>2494</span>  *
<span class='line'>2495</span>  * This method reads data from a file and computes its hash using the MD5
<span class='line'>2496</span>  * algorithm. The file can be specified as a string containing the file path or
<span class='line'>2497</span>  * as an nsIFile object.
<span class='line'>2498</span>  *
<span class='line'>2499</span>  * @public
<span class='line'>2500</span>  * @static
<span class='line'>2501</span>  * @function
<span class='line'>2502</span>  * @param {String|nsIFile} aFile  This is the file given as a file path or an nsIFile object
<span class='line'>2503</span>  * @return {String}               The resulting hash as a hex string; an empty string is returned if the file is empty or cannot be read
<span class='line'>2504</span>  * @type                          String
<span class='line'>2505</span>  */</span><span class="WHIT">
<span class='line'>2506</span> </span><span class="NAME">GREUtils.CryptoHash.md5sum</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.md5FromFile</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2507</span> 
<span class='line'>2508</span> 
<span class='line'>2509</span> </span><span class="COMM">/**
<span class='line'>2510</span>  * Computes the SHA-1 hash of a string.
<span class='line'>2511</span>  *
<span class='line'>2512</span>  * This method takes a UTF-8 string and computes its hash using the SHA-1 algorithm.
<span class='line'>2513</span>  *
<span class='line'>2514</span>  * @public
<span class='line'>2515</span>  * @static
<span class='line'>2516</span>  * @function
<span class='line'>2517</span>  * @param {String} str          This is the UTF-8 string to compute the hash for
<span class='line'>2518</span>  * @return {String}             The resulting hash as a hex string
<span class='line'>2519</span>  * @type                        String
<span class='line'>2520</span>  */</span><span class="WHIT">
<span class='line'>2521</span> </span><span class="NAME">GREUtils.CryptoHash.sha1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2522</span> 
<span class='line'>2523</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.crypt</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"SHA1"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2524</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2525</span> 
<span class='line'>2526</span> 
<span class='line'>2527</span> </span><span class="COMM">/**
<span class='line'>2528</span>  * Computes the SHA-256 hash of a string.
<span class='line'>2529</span>  *
<span class='line'>2530</span>  * This method takes a UTF-8 string and computes its hash using the SHA-256 algorithm.
<span class='line'>2531</span>  *
<span class='line'>2532</span>  * @public
<span class='line'>2533</span>  * @static
<span class='line'>2534</span>  * @function
<span class='line'>2535</span>  * @param {String} str          This is the UTF-8 string to compute the hash for
<span class='line'>2536</span>  * @return {String}             The resulting hash as a hex string
<span class='line'>2537</span>  * @type                        String
<span class='line'>2538</span>  */</span><span class="WHIT">
<span class='line'>2539</span> </span><span class="NAME">GREUtils.CryptoHash.sha256</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2540</span> 
<span class='line'>2541</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.CryptoHash.crypt</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"SHA256"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2542</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2543</span> 
<span class='line'>2544</span> </span><span class="COMM">/**
<span class='line'>2545</span>  * Returns the two-digit hexadecimal representation of a byte value.
<span class='line'>2546</span>  *
<span class='line'>2547</span>  * @public
<span class='line'>2548</span>  * @static
<span class='line'>2549</span>  * @function
<span class='line'>2550</span>  * @param {String} charCode     This is the byte value
<span class='line'>2551</span>  * @return {String}             The two-digit hexadecimal representation of the byte value
<span class='line'>2552</span>  * @type                        String
<span class='line'>2553</span>  */</span><span class="WHIT">
<span class='line'>2554</span> </span><span class="NAME">GREUtils.CryptoHash.toHexString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">charCode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2555</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"0"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">charCode.toString</span><span class="PUNC">(</span><span class="NUMB">16</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">slice</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2556</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2557</span> 
<span class='line'>2558</span> </span><span class="COMM">/**
<span class='line'>2559</span>  * Returns the hexadecimal representation of an array of byte values.
<span class='line'>2560</span>  *
<span class='line'>2561</span>  * This method takes an array of byte values and returns a string containing the
<span class='line'>2562</span>  * hexadecimal representation of each of the byte values in the array. Each byte
<span class='line'>2563</span>  * value will be represented as a two-digit hexadecimal value.
<span class='line'>2564</span>  *
<span class='line'>2565</span>  * @public
<span class='line'>2566</span>  * @static
<span class='line'>2567</span>  * @function
<span class='line'>2568</span>  * @param {Array} data        This is the array of byte values
<span class='line'>2569</span>  * @return {String}           The hexadecimal representation of the array of byte values
<span class='line'>2570</span>  * @type                      String
<span class='line'>2571</span>  */</span><span class="WHIT">
<span class='line'>2572</span> </span><span class="NAME">GREUtils.CryptoHash.arrayToHexString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2573</span> 
<span class='line'>2574</span>   	</span><span class="COMM">// convert the binary hash data to a hex string.</span><span class="WHIT">
<span class='line'>2575</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">s</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2576</span> 	</span><span class="KEYW">for</span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2577</span> 		</span><span class="NAME">s.push</span><span class="PUNC">(</span><span class="NAME">GREUtils.CryptoHash.toHexString</span><span class="PUNC">(</span><span class="NAME">data.charCodeAt</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2578</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2579</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">s.join</span><span class="PUNC">(</span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2580</span> 
<span class='line'>2581</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2582</span> </span><span class="COMM">/**
<span class='line'>2583</span>  * A set of utility functions for character set conversions.
<span class='line'>2584</span>  * 
<span class='line'>2585</span>  * @public
<span class='line'>2586</span>  * @name GREUtils.Charset
<span class='line'>2587</span>  * @namespace GREUtils.Charset
<span class='line'>2588</span>  */</span><span class="WHIT">
<span class='line'>2589</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Charset'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2590</span> 
<span class='line'>2591</span> </span><span class="COMM">/**
<span class='line'>2592</span>  * Converts a string to Unicode.
<span class='line'>2593</span>  *
<span class='line'>2594</span>  * This method takes a string encoded in the character "charset", and returns the corresponding string encoded in Unicode.
<span class='line'>2595</span>  * If "charset" is not given then string is assumed to be encoded in "UTF-8". 
<span class='line'>2596</span>  *  
<span class='line'>2597</span>  * @public
<span class='line'>2598</span>  * @static
<span class='line'>2599</span>  * @function
<span class='line'>2600</span>  * @param {String} text         This is the string to convert to Unicode
<span class='line'>2601</span>  * @param {String} charset      This is the character set the string is encoded in. 
<span class='line'>2602</span>  * @return {String}             The string encoded in Unicode if conversion succeeds; otherwise the original string is returned
<span class='line'>2603</span>  */</span><span class="WHIT">
<span class='line'>2604</span> </span><span class="NAME">GREUtils.Charset.convertToUnicode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2605</span> 	
<span class='line'>2606</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2607</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">conv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/intl/scriptableunicodeconverter"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIScriptableUnicodeConverter"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2608</span>         </span><span class="NAME">conv.charset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"UTF-8"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2609</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">conv.ConvertToUnicode</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2610</span>     </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2611</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.Charset.convertToUnicode: '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2612</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">text</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2613</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2614</span> 	
<span class='line'>2615</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2616</span> 
<span class='line'>2617</span> </span><span class="COMM">/**
<span class='line'>2618</span>  * Converts a Unicode string to the given character set encoding.
<span class='line'>2619</span>  *
<span class='line'>2620</span>  * This method takes a string encoded in Unicode, and returns the corresponding string encoded in "charset".
<span class='line'>2621</span>  * If "charset" is not given then the string will be converted to "UTF-8".
<span class='line'>2622</span>  *  
<span class='line'>2623</span>  * @public
<span class='line'>2624</span>  * @static
<span class='line'>2625</span>  * @function
<span class='line'>2626</span>  * @param {String} text         This is the Unicode string to convert
<span class='line'>2627</span>  * @param {String} charset      This is the character set encoding to convert to
<span class='line'>2628</span>  * @return {String}             The string encoded in "charset" if conversion succeeds; otherwise the original string is returned
<span class='line'>2629</span>  */</span><span class="WHIT">
<span class='line'>2630</span> </span><span class="NAME">GREUtils.Charset.convertFromUnicode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2631</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2632</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">conv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/intl/scriptableunicodeconverter"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIScriptableUnicodeConverter"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2633</span>         </span><span class="NAME">conv.charset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"UTF-8"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2634</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">conv.ConvertFromUnicode</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2635</span>     </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ex</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2636</span> 		</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.Charset.convertFromUnicode: '</span><span class="PUNC">+</span><span class="NAME">ex.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2637</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">text</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2638</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2639</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2640</span> 
<span class='line'>2641</span> 
<span class='line'>2642</span> </span><span class="COMM">/**
<span class='line'>2643</span>  * Converts a string from one character set encoding to another.
<span class='line'>2644</span>  * 
<span class='line'>2645</span>  * This method takes a string encoded in character set "in_charset"
<span class='line'>2646</span>  * and returns the corresponding string encoded in character set "out_charset".
<span class='line'>2647</span>  *
<span class='line'>2648</span>  * @public
<span class='line'>2649</span>  * @static
<span class='line'>2650</span>  * @function
<span class='line'>2651</span>  * @param {String} text         This is the string to convert
<span class='line'>2652</span>  * @param {String} in_charset   This is the character set used to encode the string
<span class='line'>2653</span>  * @param {String} out_charset  This is the character set encoding the string is to be converted to
<span class='line'>2654</span>  * @return {String}             A string encoded using the given character set "out_charset" if conversion succeeds; otherwise the original string is returned
<span class='line'>2655</span>  */</span><span class="WHIT">
<span class='line'>2656</span> </span><span class="NAME">GREUtils.Charset.convertCharset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">in_charset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">out_charset</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2657</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.convertFromUnicode</span><span class="PUNC">(</span><span class="NAME">this.convertToUnicode</span><span class="PUNC">(</span><span class="NAME">text</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">in_charset</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">out_charset</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2658</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2659</span> </span><span class="COMM">/**
<span class='line'>2660</span>  * A set of utility functions to encode and decode JSON strings.
<span class='line'>2661</span>  *
<span class='line'>2662</span>  *  XPCOM BASE Native JSON Services
<span class='line'>2663</span>  *  It is very faster then javascript implemention.
<span class='line'>2664</span>  *
<span class='line'>2665</span>  * @public
<span class='line'>2666</span>  * @name GREUtils.JSON
<span class='line'>2667</span>  * @namespace GREUtils.JSON
<span class='line'>2668</span>  */</span><span class="WHIT">
<span class='line'>2669</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.JSON'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2670</span> 
<span class='line'>2671</span> </span><span class="NAME">GREUtils.JSON</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2672</span> 	</span><span class="NAME">_native</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>2673</span> 	</span><span class="NAME">_jsonService</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT">
<span class='line'>2674</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2675</span> 
<span class='line'>2676</span> </span><span class="COMM">/**
<span class='line'>2677</span>  * Returns the XPCOM service that implements the nsIJSON interface
<span class='line'>2678</span>  *
<span class='line'>2679</span>  * @public
<span class='line'>2680</span>  * @static
<span class='line'>2681</span>  * @function
<span class='line'>2682</span>  * @return {Object}                       The nsIJSON service
<span class='line'>2683</span>  * @type                                  nsIJSON
<span class='line'>2684</span>  */</span><span class="WHIT">
<span class='line'>2685</span> </span><span class="NAME">GREUtils.JSON.getJSONService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2686</span> 
<span class='line'>2687</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this._jsonService</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2688</span> 		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">jsonService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"json"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2689</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">jsonService</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2690</span> 			</span><span class="NAME">this._native</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2691</span> 			</span><span class="NAME">this._jsonService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">jsonService</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2692</span> 		</span><span class="PUNC">}</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2693</span> 			</span><span class="COMM">// use json javascript code</span><span class="WHIT">
<span class='line'>2694</span> 			</span><span class="NAME">this._native</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2695</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2696</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>2697</span>  	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._jsonService</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2698</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2699</span> 
<span class='line'>2700</span> 
<span class='line'>2701</span> </span><span class="COMM">/**
<span class='line'>2702</span>  * Decodes a JSON string, returning the JavaScript object it represents.
<span class='line'>2703</span>  *
<span class='line'>2704</span>  * @public
<span class='line'>2705</span>  * @static
<span class='line'>2706</span>  * @function
<span class='line'>2707</span>  * @param {String} aJSONString            This is the JSON string
<span class='line'>2708</span>  * @return {Object}                       The JavaScript object represented by the JSON string
<span class='line'>2709</span>  * @type                                  Object
<span class='line'>2710</span>  */</span><span class="WHIT">
<span class='line'>2711</span> </span><span class="NAME">GREUtils.JSON.decode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aJSONString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2712</span>  	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.JSON.getJSONService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">decode</span><span class="PUNC">(</span><span class="NAME">aJSONString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2713</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2714</span> 
<span class='line'>2715</span> 
<span class='line'>2716</span> </span><span class="COMM">/**
<span class='line'>2717</span>  * Encodes a JavaScript object into a JSON string.
<span class='line'>2718</span>  *
<span class='line'>2719</span>  * @public
<span class='line'>2720</span>  * @static
<span class='line'>2721</span>  * @function
<span class='line'>2722</span>  * @param {Object} aJSObject              This is the JavaScript object to encode
<span class='line'>2723</span>  * @return {String} JSON string           The JSON representation of the JavaScript object
<span class='line'>2724</span>  * @type                                  Object
<span class='line'>2725</span>  */</span><span class="WHIT">
<span class='line'>2726</span> </span><span class="NAME">GREUtils.JSON.encode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aJSObject</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2727</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.JSON.getJSONService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">encode</span><span class="PUNC">(</span><span class="NAME">aJSObject</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2728</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2729</span> 
<span class='line'>2730</span> 
<span class='line'>2731</span> </span><span class="COMM">/**
<span class='line'>2732</span>  * Decodes a JSON string read from an input stream, returning the JavaScript object it represents.
<span class='line'>2733</span>  *
<span class='line'>2734</span>  * @public
<span class='line'>2735</span>  * @static
<span class='line'>2736</span>  * @function
<span class='line'>2737</span>  * @param {nsIInputStream} stream         This is the input stream from which to read the JSON string
<span class='line'>2738</span>  * @param {Number} contentLength          This is the length of the JSON string to read from the input stream
<span class='line'>2739</span>  * @return {Object}                       The JavaScript object represented by the JSON string
<span class='line'>2740</span>  * @type                                  Object
<span class='line'>2741</span>  */</span><span class="WHIT">
<span class='line'>2742</span> </span><span class="NAME">GREUtils.JSON.decodeFromStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">contentLength</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2743</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.JSON.getJSONService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">decodeFromStream</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">contentLength</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2744</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2745</span> 
<span class='line'>2746</span> 
<span class='line'>2747</span> </span><span class="COMM">/**
<span class='line'>2748</span>  * Encodes a JavaScript object into JSON format, writing it to a stream.
<span class='line'>2749</span>  *
<span class='line'>2750</span>  * If byte-order mark (BOM) is desired, set writeBOM to true; otherwise set writeBOM to false.
<span class='line'>2751</span>  *
<span class='line'>2752</span>  * @public
<span class='line'>2753</span>  * @static
<span class='line'>2754</span>  * @function
<span class='line'>2755</span>  * @param {nsIOutputStream} stream        Thisis the output stream to which to write the JSON string
<span class='line'>2756</span>  * @param {Object} value                  This is the JavaScript object to encode
<span class='line'>2757</span>  * @param {String} charset                This is the character set encoding to use on the JSON string; defaults to "UTF-8"
<span class='line'>2758</span>  * @param {Boolean} writeBOM              This flag indicates whether to write a byte-order mark (BOM) into the stream; defaults to "false"
<span class='line'>2759</span>  * @return
<span class='line'>2760</span>  * @type                                  void
<span class='line'>2761</span>  */</span><span class="WHIT">
<span class='line'>2762</span> </span><span class="NAME">GREUtils.JSON.encodeToStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">writeBOM</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2763</span> 	</span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">'UTF-8'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2764</span> 	</span><span class="NAME">writeBOM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">writeBOM</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2765</span> 
<span class='line'>2766</span> 	</span><span class="NAME">GREUtils.JSON.getJSONService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">encodeToStream</span><span class="PUNC">(</span><span class="NAME">stream</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">charset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">writeBOM</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2767</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2768</span> 
<span class='line'>2769</span> 
<span class='line'>2770</span> </span><span class="COMM">/**
<span class='line'>2771</span>  * Decodes a JSON string read from a file, returning the JavaScript object it represents.
<span class='line'>2772</span>  *
<span class='line'>2773</span>  * If the file cannot be read, null is returned.
<span class='line'>2774</span>  *
<span class='line'>2775</span>  * @public
<span class='line'>2776</span>  * @static
<span class='line'>2777</span>  * @function
<span class='line'>2778</span>  * @param {String} filename               This is the file path from which to read the JSON string
<span class='line'>2779</span>  * @return {Object}                       The JavaScript object represented by the JSON string
<span class='line'>2780</span>  * @type                                  Object
<span class='line'>2781</span>  */</span><span class="WHIT">
<span class='line'>2782</span> </span><span class="NAME">GREUtils.JSON.decodeFromFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2783</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileInputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getInputStream</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"rb"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2784</span> 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">fileInputStream</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2785</span> 
<span class='line'>2786</span> 	</span><span class="COMM">// return GREUtils.JSON.decodeFromStream(fileInputStream, fileInputStream.available());</span><span class="WHIT">
<span class='line'>2787</span> 
<span class='line'>2788</span>     </span><span class="COMM">// native json decodeFromStream buggy?</span><span class="WHIT">
<span class='line'>2789</span>     </span><span class="COMM">// try to write self</span><span class="WHIT">
<span class='line'>2790</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">aJSONString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.readAllBytes</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2791</span> 	</span><span class="NAME">aJSONString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Charset.convertToUnicode</span><span class="PUNC">(</span><span class="NAME">aJSONString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2792</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.JSON.decode</span><span class="PUNC">(</span><span class="NAME">aJSONString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2793</span> 
<span class='line'>2794</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2795</span> 
<span class='line'>2796</span> 
<span class='line'>2797</span> </span><span class="COMM">/**
<span class='line'>2798</span>  * Encodes a JavaScript object into JSON format, writing it to a file.
<span class='line'>2799</span>  *
<span class='line'>2800</span>  * The JSON string will first be encoded in "UTF-8" before being written to the file.
<span class='line'>2801</span>  *
<span class='line'>2802</span>  * @public
<span class='line'>2803</span>  * @static
<span class='line'>2804</span>  * @function
<span class='line'>2805</span>  * @param {nsIOutputStream} filename      This is the output file to which to write the JSON string
<span class='line'>2806</span>  * @param {Object} value                  This is the JavaScript object to encode
<span class='line'>2807</span>  * @return
<span class='line'>2808</span>  * @type                                  void
<span class='line'>2809</span>  */</span><span class="WHIT">
<span class='line'>2810</span> </span><span class="NAME">GREUtils.JSON.encodeToFile</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2811</span> 
<span class='line'>2812</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fileOutputStream</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getOutputStream</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"w"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2813</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">fileOutputStream</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2814</span> 
<span class='line'>2815</span>     </span><span class="COMM">// GREUtils.JSON.encodeToStream(fileOutputStream, value);</span><span class="WHIT">
<span class='line'>2816</span>     </span><span class="COMM">// native json decodeFromStream buggy?</span><span class="WHIT">
<span class='line'>2817</span>     </span><span class="COMM">// try to write self</span><span class="WHIT">
<span class='line'>2818</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">aJSONString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.JSON.encode</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2819</span> 	</span><span class="NAME">aJSONString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Charset.convertFromUnicode</span><span class="PUNC">(</span><span class="NAME">aJSONString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"UTF-8"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2820</span> 	</span><span class="NAME">GREUtils.File.writeAllBytes</span><span class="PUNC">(</span><span class="NAME">filename</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aJSONString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2821</span>     </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2822</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2823</span> </span><span class="COMM">/**
<span class='line'>2824</span>  * A set of utility functions for playing sounds.
<span class='line'>2825</span>  *
<span class='line'>2826</span>  * @public
<span class='line'>2827</span>  * @name GREUtils.Sound
<span class='line'>2828</span>  * @namespace GREUtils.Sound
<span class='line'>2829</span>  */</span><span class="WHIT">
<span class='line'>2830</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Sound'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2831</span> 
<span class='line'>2832</span> 
<span class='line'>2833</span> </span><span class="COMM">/**
<span class='line'>2834</span>  * Returns the XPCOM service that implements the nsISound interface
<span class='line'>2835</span>  *
<span class='line'>2836</span>  * @public
<span class='line'>2837</span>  * @static
<span class='line'>2838</span>  * @function
<span class='line'>2839</span>  * @return {Object}                       The nsISound service
<span class='line'>2840</span>  * @type                                  nsISound
<span class='line'>2841</span>  */</span><span class="WHIT">
<span class='line'>2842</span> </span><span class="NAME">GREUtils.Sound.getSoundService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2843</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"sound"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2844</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2845</span> 
<span class='line'>2846</span> 
<span class='line'>2847</span> </span><span class="COMM">/**
<span class='line'>2848</span>  * Plays the sound file located at the given URL.
<span class='line'>2849</span>  *
<span class='line'>2850</span>  * @public
<span class='line'>2851</span>  * @static
<span class='line'>2852</span>  * @function
<span class='line'>2853</span>  * @param {String} sURL                   This is the URL pointing to the location of the sound file
<span class='line'>2854</span>  * @return
<span class='line'>2855</span>  * @type                                  void
<span class='line'>2856</span>  */</span><span class="WHIT">
<span class='line'>2857</span> </span><span class="NAME">GREUtils.Sound.play</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2858</span>     </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getURL</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2859</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">snd</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Sound.getSoundService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2860</span>     </span><span class="NAME">snd.init</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2861</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">snd.play</span><span class="PUNC">(</span><span class="NAME">mURL</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2862</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2863</span> 
<span class='line'>2864</span> 
<span class='line'>2865</span> </span><span class="COMM">/**
<span class='line'>2866</span>  * Generates the system beep sound.
<span class='line'>2867</span>  *
<span class='line'>2868</span>  * @public
<span class='line'>2869</span>  * @static
<span class='line'>2870</span>  * @function
<span class='line'>2871</span>  * @return
<span class='line'>2872</span>  * @type                                  void
<span class='line'>2873</span>  */</span><span class="WHIT">
<span class='line'>2874</span> </span><span class="NAME">GREUtils.Sound.beep</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2875</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.Sound.getSoundService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">beep</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2876</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2877</span> 
<span class='line'>2878</span> 
<span class='line'>2879</span> </span><span class="COMM">/**
<span class='line'>2880</span>  * Plays a system sound.
<span class='line'>2881</span>  *
<span class='line'>2882</span>  * @public
<span class='line'>2883</span>  * @static
<span class='line'>2884</span>  * @function
<span class='line'>2885</span>  * @param {String} sURL                   This is the system sound identifier
<span class='line'>2886</span>  * @return
<span class='line'>2887</span>  * @type                                  void
<span class='line'>2888</span>  */</span><span class="WHIT">
<span class='line'>2889</span> </span><span class="NAME">GREUtils.Sound.playSystemSound</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2890</span>     </span><span class="NAME">mURL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getURL</span><span class="PUNC">(</span><span class="NAME">sURL</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2891</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">snd</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getSoundService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2892</span>     </span><span class="NAME">snd.init</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2893</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">snd.playSystemSound</span><span class="PUNC">(</span><span class="NAME">mURL</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2894</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2895</span> </span><span class="COMM">/**
<span class='line'>2896</span>  * A set of utility functions used to manipulate preference data.
<span class='line'>2897</span>  *
<span class='line'>2898</span>  * @public
<span class='line'>2899</span>  * @name GREUtils.Pref
<span class='line'>2900</span>  * @namespace GREUtils.Pref
<span class='line'>2901</span>  */</span><span class="WHIT">
<span class='line'>2902</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Pref'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2903</span> 
<span class='line'>2904</span> 
<span class='line'>2905</span> </span><span class="COMM">/**
<span class='line'>2906</span>  * Returns the XPCom service that implements the nsIPrefBranch2 interface.
<span class='line'>2907</span>  *
<span class='line'>2908</span>  * @public
<span class='line'>2909</span>  * @static
<span class='line'>2910</span>  * @function
<span class='line'>2911</span>  * @return {Object} nsIPrefBranch2      The preference service
<span class='line'>2912</span>  * @type                                nsIPrefBranch2
<span class='line'>2913</span>  */</span><span class="WHIT">
<span class='line'>2914</span> </span><span class="NAME">GREUtils.Pref.getPrefService</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2915</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/preferences-service;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIPrefBranch2"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2916</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2917</span> 
<span class='line'>2918</span> 
<span class='line'>2919</span> </span><span class="COMM">/**
<span class='line'>2920</span>  * Returns preference value by key.
<span class='line'>2921</span>  *
<span class='line'>2922</span>  * This method will automatically detect the type of preference (string, int, boolean)
<span class='line'>2923</span>  * and return the preference value accordingly.
<span class='line'>2924</span>  *
<span class='line'>2925</span>  * @public
<span class='line'>2926</span>  * @static
<span class='line'>2927</span>  * @function
<span class='line'>2928</span>  * @param {String} prefName             This is the name of the preference
<span class='line'>2929</span>  * @param {Object} prefService          This is the preferences service to use; if null, the default preferences service will be used
<span class='line'>2930</span>  * @return {Object}                     The preference value
<span class='line'>2931</span>  * @type                                Object
<span class='line'>2932</span>  */</span><span class="WHIT">
<span class='line'>2933</span> </span><span class="NAME">GREUtils.Pref.getPref</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2934</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">prefName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2935</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">prefs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">GREUtils.Pref.getPrefService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2936</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="PUNC">(</span><span class="STRN">"nsIPrefBranch"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2937</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">prefs.getPrefType</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2938</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_STRING</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2939</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">prefs.getCharPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2940</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_INT</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2941</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">prefs.getIntPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2942</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_BOOL</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2943</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">prefs.getBoolPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2944</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2945</span> 
<span class='line'>2946</span> 
<span class='line'>2947</span> </span><span class="COMM">/**
<span class='line'>2948</span>  * Sets the state of individual preferences
<span class='line'>2949</span>  *
<span class='line'>2950</span>  * This method will automatically detect the type of preference (string, int, boolean)
<span class='line'>2951</span>  * and set the preference value accordingly.
<span class='line'>2952</span>  *
<span class='line'>2953</span>  * @public
<span class='line'>2954</span>  * @static
<span class='line'>2955</span>  * @function
<span class='line'>2956</span>  * @param {String} prefName             This is the name of the preference
<span class='line'>2957</span>  * @param {Object} prefValue            This is the value to which to set the preference
<span class='line'>2958</span>  * @param {Object} prefService          This is the preferences service to use; if null, the default preferences service will be used
<span class='line'>2959</span>  * @return
<span class='line'>2960</span>  * @type                                void
<span class='line'>2961</span>  */</span><span class="WHIT">
<span class='line'>2962</span> 
<span class='line'>2963</span> </span><span class="NAME">GREUtils.Pref.setPref</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2964</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">prefName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2965</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2966</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">prefs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">GREUtils.Pref.getPrefService</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2967</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.Ci</span><span class="PUNC">(</span><span class="STRN">"nsIPrefBranch"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2968</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">prefs.getPrefType</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2969</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_STRING</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2970</span>         </span><span class="NAME">prefs.setCharPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2971</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_INT</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2972</span>         </span><span class="NAME">prefs.setIntPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2973</span>     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">nsIPrefBranch.PREF_BOOL</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>2974</span>         </span><span class="NAME">prefs.setBoolPref</span><span class="PUNC">(</span><span class="NAME">prefName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2975</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2976</span> </span><span class="COMM">/**
<span class='line'>2977</span>  * A set of utility functions to create various types of dialogs and specialize windows.
<span class='line'>2978</span>  *
<span class='line'>2979</span>  * @public
<span class='line'>2980</span>  * @name GREUtils.Dialog
<span class='line'>2981</span>  * @namespace GREUtils.Dialog
<span class='line'>2982</span>  */</span><span class="WHIT">
<span class='line'>2983</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Dialog'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>2984</span> 
<span class='line'>2985</span> 
<span class='line'>2986</span> </span><span class="COMM">/**
<span class='line'>2987</span>  * Creates a new window and automatically adds it to the watch list.
<span class='line'>2988</span>  *
<span class='line'>2989</span>  * @param {nsIDOMWindow} aParent                    This is the parent window, if any, or null if no parent window
<span class='line'>2990</span>  * @param {String} aUrl                             This is the URL to open in the newly created window. The URL must be appropriately escaped, and can be null
<span class='line'>2991</span>  * @param {String} aName                            This is the name to assign to the newly created window. Defaults to "_blank" If a window with this name already exists, that window may be returned instead
<span class='line'>2992</span>  * @param {String} aFeatures                        This is the window features to apply to the new window. Defaults to "chrome,centerscreen"
<span class='line'>2993</span>  * @param {nsISupportsArray|nsIArray} aArguments    This is the list of extra argument(s) to be attached to the new window as the window.arguments property. An nsISupportsArray will be unwound into multiple arguments (but not recursively!). Can be null, in which case the window.arguments property will not be set on the new window. Can also be an nsIArray.
<span class='line'>2994</span>  * @return {nsIDOMWindow}                           The new window
<span class='line'>2995</span>  * @type                                            nsIDOMWindow
<span class='line'>2996</span>  */</span><span class="WHIT">
<span class='line'>2997</span> </span><span class="NAME">GREUtils.Dialog.openWindow</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">  </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aParent</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aUrl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aFeatures</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>2998</span> 
<span class='line'>2999</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">parent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aParent</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3000</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">name</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">"_blank"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3001</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">args</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3002</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aFeatures</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">"chrome,centerscreen"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3003</span> 
<span class='line'>3004</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">ww</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"window-watcher"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3005</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">ww.openWindow</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aUrl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">name</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">features</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">args</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3006</span> 
<span class='line'>3007</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3008</span> 
<span class='line'>3009</span> 
<span class='line'>3010</span> </span><span class="COMM">/**
<span class='line'>3011</span>  * Creates a top-level Dialog window. The dialog will be screen-centered by default.
<span class='line'>3012</span>  *
<span class='line'>3013</span>  * @public
<span class='line'>3014</span>  * @static
<span class='line'>3015</span>  * @function
<span class='line'>3016</span>  * @param {String} aUrl                             This is the URL to open in the newly created dialog window
<span class='line'>3017</span>  * @param {String} aName                            This is the name to assign to the dialog window
<span class='line'>3018</span>  * @param {nsISupportsArray|nsIArray} aArguments    This is the list of extra argument(s) to be attached to the new dialog window as the window.arguments property. An nsISupportsArray will be unwound into multiple arguments (but not recursively!). Can be null, in which case the window.arguments property will not be set on the new dialog window. Can also be an nsIArray.
<span class='line'>3019</span>  * @param {Number} posX                             This is the X screen coordinate of the dialog window
<span class='line'>3020</span>  * @param {Number} posY                             This is the Y screen coordinate of the dialog window
<span class='line'>3021</span>  * @param {Number} width                            This is the width of the dialog window
<span class='line'>3022</span>  * @param {Number} height                           This is the height of the dialog window
<span class='line'>3023</span>  * @return {nsIDOMWindow}                           The new dialog window
<span class='line'>3024</span>  * @type                                            nsIDOMWindow
<span class='line'>3025</span>  */</span><span class="WHIT">
<span class='line'>3026</span> </span><span class="NAME">GREUtils.Dialog.openDialog</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">posX</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">posY</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3027</span> 
<span class='line'>3028</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"chrome,dialog,dependent=yes,resize=yes"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3029</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">&lt;=</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3030</span> 		</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",centerscreen"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3031</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3032</span> 	</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3033</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">posX</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>3034</span> 			</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenX="</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">posX</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3035</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">posY</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>3036</span> 			</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenY="</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">posY</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3037</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">width</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>3038</span> 			</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",width="</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3039</span> 		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">height</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>3040</span> 			</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",height="</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3041</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3042</span> 
<span class='line'>3043</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dialog.openWindow</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">features</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3044</span> 
<span class='line'>3045</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3046</span> 
<span class='line'>3047</span> 
<span class='line'>3048</span> </span><span class="COMM">/**
<span class='line'>3049</span>  * Creates a top-level modal dialog window. The dialog will be screen-centered by default.
<span class='line'>3050</span>  *
<span class='line'>3051</span>  * @public
<span class='line'>3052</span>  * @static
<span class='line'>3053</span>  * @function
<span class='line'>3054</span>  * @param {String} aUrl                             This is the URL to open in the newly created modal dialog
<span class='line'>3055</span>  * @param {String} aName                            This is the name to assign to the modal dialog
<span class='line'>3056</span>  * @param {nsISupportsArray|nsIArray} aArguments    This is the list of extra argument(s) to be attached to the new modal dialog as the window.arguments property. An nsISupportsArray will be unwound into multiple arguments (but not recursively!). Can be null, in which case the window.arguments property will not be set on the new modal dialog. Can also be an nsIArray.
<span class='line'>3057</span>  * @param {Number} posX                             This is the X screen coordinate of the modal dialog
<span class='line'>3058</span>  * @param {Number} posY                             This is the Y screen coordinate of the modal dialog
<span class='line'>3059</span>  * @param {Number} width                            This is the width of the modal dialog
<span class='line'>3060</span>  * @param {Number} height                           This is the height of the modal dialog
<span class='line'>3061</span>  * @return {nsIDOMWindow}                           The new modal dialog
<span class='line'>3062</span>  * @type                                            nsIDOMWindow
<span class='line'>3063</span>  */</span><span class="WHIT">
<span class='line'>3064</span> </span><span class="NAME">GREUtils.Dialog.openModalDialog</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">posX</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">posY</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">width</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">height</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3065</span> 
<span class='line'>3066</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"chrome,dialog,dependent=no,modal,resize=yes"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3067</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">&lt;=</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3068</span> 		</span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",centerscreen"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3069</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3070</span> 	</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3071</span> 	    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">posX</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenX="</span><span class="PUNC">+</span><span class="NAME">posX</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3072</span> 	    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">posY</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenY="</span><span class="PUNC">+</span><span class="NAME">posY</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3073</span> 	    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">width</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",width="</span><span class="PUNC">+</span><span class="NAME">width</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3074</span> 	    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">height</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",height="</span><span class="PUNC">+</span><span class="NAME">height</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3075</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3076</span> 
<span class='line'>3077</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dialog.openWindow</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">features</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3078</span> 
<span class='line'>3079</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3080</span> 
<span class='line'>3081</span> 
<span class='line'>3082</span> </span><span class="COMM">/**
<span class='line'>3083</span>  * Creates a top-level, full screen window.
<span class='line'>3084</span>  *
<span class='line'>3085</span>  * @public
<span class='line'>3086</span>  * @static
<span class='line'>3087</span>  * @function
<span class='line'>3088</span>  * @param {String} aUrl                             This is the URL to open in the newly created modal dialog
<span class='line'>3089</span>  * @param {String} aName                            This is the name to assign to the modal dialog
<span class='line'>3090</span>  * @return {nsIDOMWindow}                           The new full-screen window
<span class='line'>3091</span>  * @type                                            nsIDOMWindow
<span class='line'>3092</span>  */</span><span class="WHIT">
<span class='line'>3093</span> </span><span class="NAME">GREUtils.Dialog.openFullScreen</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3094</span> 
<span class='line'>3095</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"chrome,dialog=no,resize=no,titlebar=no,fullscreen=yes"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3096</span>     </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",x=0,y=0"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3097</span>     </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenX="</span><span class="PUNC">+</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3098</span>     </span><span class="NAME">features</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">",screenY="</span><span class="PUNC">+</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3099</span> 
<span class='line'>3100</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.Dialog.openWindow</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aURL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">features</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aArguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3101</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3102</span> 
<span class='line'>3103</span> 
<span class='line'>3104</span> </span><span class="COMM">/**
<span class='line'>3105</span>  * Returns the XPCOM service that implements the nsIFilePicker interface.
<span class='line'>3106</span>  *
<span class='line'>3107</span>  * @public
<span class='line'>3108</span>  * @static
<span class='line'>3109</span>  * @function
<span class='line'>3110</span>  * @return {nsIFilePicker}                          The nsIFilePicker service
<span class='line'>3111</span>  * @type                                            nsIFilePicker
<span class='line'>3112</span>  */</span><span class="WHIT">
<span class='line'>3113</span> </span><span class="NAME">GREUtils.Dialog.getFilePicker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3114</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getService</span><span class="PUNC">(</span><span class="STRN">"@mozilla.org/filepicker;1"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFilePicker"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3115</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3116</span> 
<span class='line'>3117</span> </span><span class="COMM">/**
<span class='line'>3118</span>  * Shows a file picker dialog window to allow user to select a file.
<span class='line'>3119</span>  *
<span class='line'>3120</span>  * The directory that the file open/save dialog initially displays can be specified
<span class='line'>3121</span>  * through the "sDir" parameter. This parameter can be either a string containing the
<span class='line'>3122</span>  * directory path or a nsILocalFile object.
<span class='line'>3123</span>  *
<span class='line'>3124</span>  * @public
<span class='line'>3125</span>  * @static
<span class='line'>3126</span>  * @function
<span class='line'>3127</span>  * @param {String|nsILocalFile} sDir                This is the directory that the file open/save dialog initially displays
<span class='line'>3128</span>  * @return {String}                                         The path of the selected file, or null if no file is selected
<span class='line'>3129</span>  * @type                                            String
<span class='line'>3130</span>  */</span><span class="WHIT">
<span class='line'>3131</span> </span><span class="NAME">GREUtils.Dialog.openFilePicker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3132</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">filePicker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.getFilePicker</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3133</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3134</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">)</span><span class="PUNC">==</span><span class="STRN">"object"</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.queryInterface</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"nsIFile"</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3135</span>             </span><span class="NAME">filePicker.displayDirectory</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">sDir</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3136</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3137</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">)</span><span class="PUNC">==</span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3138</span>             </span><span class="NAME">filePicker.displayDirectory</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.File.getFile</span><span class="PUNC">(</span><span class="NAME">sDir</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3139</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3140</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3141</span>     </span><span class="NAME">filePicker.show</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3142</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">filePicker.file.path.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">filePicker.file.path</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3143</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3144</span> 
<span class='line'>3145</span> </span><span class="COMM">/**
<span class='line'>3146</span>  * Displays an alert dialog.
<span class='line'>3147</span>  *
<span class='line'>3148</span>  * Shows a top-level alert dialog with an OK button, a window title, and alert text.
<span class='line'>3149</span>  *
<span class='line'>3150</span>  * @public
<span class='line'>3151</span>  * @static
<span class='line'>3152</span>  * @function
<span class='line'>3153</span>  * @param {String} dialogTitle                      This is the title of the alert dialog
<span class='line'>3154</span>  * @param {String} dialogText                       This is the alert text
<span class='line'>3155</span>  * @return
<span class='line'>3156</span>  * @type                                            void
<span class='line'>3157</span>  */</span><span class="WHIT">
<span class='line'>3158</span> </span><span class="NAME">GREUtils.Dialog.alert</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3159</span>     </span><span class="COMM">// get a reference to the prompt service component.</span><span class="WHIT">
<span class='line'>3160</span>     </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"prompt-service"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">alert</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3161</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3162</span> 
<span class='line'>3163</span> </span><span class="COMM">/**
<span class='line'>3164</span>  * Displays a dialog prompting for user confirmation.
<span class='line'>3165</span>  *
<span class='line'>3166</span>  * Shows a top-level confirm dialog with OK and Cancel buttons, a window title, and text.
<span class='line'>3167</span>  *
<span class='line'>3168</span>  * @public
<span class='line'>3169</span>  * @static
<span class='line'>3170</span>  * @function
<span class='line'>3171</span>  * @param {String} dialogTitle                      This is the title of the confirm dialog
<span class='line'>3172</span>  * @param {String} dialogText                       This is the confirm text
<span class='line'>3173</span>  * @return {Boolean}                                "true" if OK is clicked, and "false" if Cancel is clicked
<span class='line'>3174</span>  * @type                                            Boolean
<span class='line'>3175</span>  */</span><span class="WHIT">
<span class='line'>3176</span> </span><span class="NAME">GREUtils.Dialog.confirm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3177</span>     </span><span class="COMM">// get a reference to the prompt service component.</span><span class="WHIT">
<span class='line'>3178</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"prompt-service"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">confirm</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3179</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3180</span> 
<span class='line'>3181</span> </span><span class="COMM">/**
<span class='line'>3182</span>  * Displays a dialog prompting for text input.
<span class='line'>3183</span>  *
<span class='line'>3184</span>  * Shows a top-level prompt dialog with an edit field, OK and Cancel buttons, a window title,
<span class='line'>3185</span>  * and prompt text.
<span class='line'>3186</span>  *
<span class='line'>3187</span>  * The edit field will have an initial value taken from the "value" property of the object
<span class='line'>3188</span>  * given by the "input" parameter. If the user clicks OK, the value from the edit field
<span class='line'>3189</span>  * is stored in the "value" property of the "input" object before returning.
<span class='line'>3190</span>  *
<span class='line'>3191</span>  * @public
<span class='line'>3192</span>  * @static
<span class='line'>3193</span>  * @function
<span class='line'>3194</span>  * @param {String} dialogTitle                      This is the title of the prompt dialog
<span class='line'>3195</span>  * @param {String} dialogText                       This is the prompt text
<span class='line'>3196</span>  * @param {Object} input                            This object holds the value of the edit field
<span class='line'>3197</span>  * @return {Boolean}                                "true" if OK is clicked, and "false" if Cancel is clicked
<span class='line'>3198</span>  * @type                                            Boolean
<span class='line'>3199</span>  */</span><span class="WHIT">
<span class='line'>3200</span> </span><span class="NAME">GREUtils.Dialog.prompt</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">input</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3201</span>     </span><span class="COMM">// get a reference to the prompt service component.</span><span class="WHIT">
<span class='line'>3202</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"prompt-service"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">prompt</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">input</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3203</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3204</span> 
<span class='line'>3205</span> </span><span class="COMM">/**
<span class='line'>3206</span>  * Displays a select dialog prompting user to make a selection.
<span class='line'>3207</span>  *
<span class='line'>3208</span>  * Shows a top-level select dialog with a list box of strings, OK and Cancel buttons,
<span class='line'>3209</span>  * a window title, and prompt text.
<span class='line'>3210</span>  *
<span class='line'>3211</span>  * If the user clicks OK, the "value" property of the "selected" object will be set
<span class='line'>3212</span>  * to the index of the the selected item before returning.
<span class='line'>3213</span>  *
<span class='line'>3214</span>  * @public
<span class='line'>3215</span>  * @static
<span class='line'>3216</span>  * @function
<span class='line'>3217</span>  * @param {String} dialogTitle                      This is the title of the select dialog
<span class='line'>3218</span>  * @param {String} dialogText                       This is the prompt text
<span class='line'>3219</span>  * @param {String[]} list                           This is an array of strings for selection
<span class='line'>3220</span>  * @param {Object} selected                         This object holds the index of the selected item
<span class='line'>3221</span>  * @return {Boolean}                                "true" if OK is clicked, and "false" if Cancel is clicked
<span class='line'>3222</span>  * @type                                            Boolean
<span class='line'>3223</span>  */</span><span class="WHIT">
<span class='line'>3224</span> </span><span class="NAME">GREUtils.Dialog.select</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">list</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">selected</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3225</span>     </span><span class="COMM">// get a reference to the prompt service component.</span><span class="WHIT">
<span class='line'>3226</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"prompt-service"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">select</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogTitle</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dialogText</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">list.length</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">list</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">selected</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3227</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3228</span> 
<span class='line'>3229</span> </span><span class="COMM">/**
<span class='line'>3230</span>  * Returns a ChromeWindow object representing the most recent window of the
<span class='line'>3231</span>  * type given by "windowName".
<span class='line'>3232</span>  *
<span class='line'>3233</span>  * If there are no windows open, null is returned.
<span class='line'>3234</span>  *
<span class='line'>3235</span>  * @public
<span class='line'>3236</span>  * @static
<span class='line'>3237</span>  * @function
<span class='line'>3238</span>  * @param {Object} windowName                       This is the type of window to return; null for all types
<span class='line'>3239</span>  * @return {Object}                                 The most recent window of the given type, or null if no such window is open
<span class='line'>3240</span>  * @type                                            ChromeWindow
<span class='line'>3241</span>  */</span><span class="WHIT">
<span class='line'>3242</span> </span><span class="NAME">GREUtils.Dialog.getMostRecentWindow</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">windowName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3243</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"window-mediator"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">getMostRecentWindow</span><span class="PUNC">(</span><span class="NAME">windowName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3244</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3245</span> 
<span class='line'>3246</span> </span><span class="COMM">/**
<span class='line'>3247</span>  * Returns all open windows of a given type in an array of ChromeWindow objects.
<span class='line'>3248</span>  *
<span class='line'>3249</span>  * Returns an empty array [] if there are no windows of the given type open.
<span class='line'>3250</span>  *
<span class='line'>3251</span>  * @public
<span class='line'>3252</span>  * @static
<span class='line'>3253</span>  * @function
<span class='line'>3254</span>  * @param {Object} windowName                       This is the type of window to enumerate; null for all types
<span class='line'>3255</span>  * @return {Object}                                 An array of ChromeWindow objects
<span class='line'>3256</span>  * @type                                            ChromeWindow[]
<span class='line'>3257</span>  */</span><span class="WHIT">
<span class='line'>3258</span> </span><span class="NAME">GREUtils.Dialog.getWindowArray</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">windowName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3259</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">enumerator</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"window-mediator"</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">getEnumerator</span><span class="PUNC">(</span><span class="NAME">windowName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3260</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">wins</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3261</span> 	</span><span class="KEYW">while</span><span class="PUNC">(</span><span class="NAME">enumerator.hasMoreElements</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3262</span> 	  </span><span class="NAME">wins.push</span><span class="PUNC">(</span><span class="NAME">enumerator.getNext</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3263</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3264</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">wins</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3265</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3266</span> </span><span class="COMM">/**
<span class='line'>3267</span>  * A set of utility functions that applications and extensions can easily use to
<span class='line'>3268</span>  * create and manage threads within the Gecko Runtime Environment.
<span class='line'>3269</span>  *
<span class='line'>3270</span>  * Each thread is represented by an nsIThread object.
<span class='line'>3271</span>  * ONLY Work with Firefox 3 or XULRunner 1.9
<span class='line'>3272</span>  *
<span class='line'>3273</span>  * @public
<span class='line'>3274</span>  * @name GREUtils.Thread
<span class='line'>3275</span>  * @namespace GREUtils.Thread
<span class='line'>3276</span>  */</span><span class="WHIT">
<span class='line'>3277</span> </span><span class="NAME">GREUtils.define</span><span class="PUNC">(</span><span class="STRN">'GREUtils.Thread'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3278</span> 
<span class='line'>3279</span> </span><span class="NAME">GREUtils.Thread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3280</span> 
<span class='line'>3281</span>     </span><span class="NAME">_threadManager</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">GREUtils.XPCOM.getUsefulService</span><span class="PUNC">(</span><span class="STRN">"thread-manager"</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3282</span> 
<span class='line'>3283</span>     </span><span class="NAME">_mainThread</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3284</span> 
<span class='line'>3285</span>     </span><span class="NAME">_workerThread</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3286</span> 
<span class='line'>3287</span>     </span><span class="NAME">reportError</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3288</span>         </span><span class="NAME">Components.utils.reportError</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3289</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3290</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3291</span> 
<span class='line'>3292</span> 
<span class='line'>3293</span> </span><span class="COMM">/**
<span class='line'>3294</span>  * Returns the XPCOM service that implements the nsIThreadManager interface
<span class='line'>3295</span>  *
<span class='line'>3296</span>  * @public
<span class='line'>3297</span>  * @static
<span class='line'>3298</span>  * @function
<span class='line'>3299</span>  * @return {Object}                     The nsIThreadManager service
<span class='line'>3300</span>  * @type                                nsIThreadManager
<span class='line'>3301</span>  */</span><span class="WHIT">
<span class='line'>3302</span> </span><span class="NAME">GREUtils.Thread.getThreadManager</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3303</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._threadManager</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3304</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3305</span> 
<span class='line'>3306</span> 
<span class='line'>3307</span> </span><span class="COMM">/**
<span class='line'>3308</span>  * Returns the main thread.
<span class='line'>3309</span>  *
<span class='line'>3310</span>  * @public
<span class='line'>3311</span>  * @static
<span class='line'>3312</span>  * @function
<span class='line'>3313</span>  * @return {Object}                     The main thread
<span class='line'>3314</span>  * @type                                nsIThread
<span class='line'>3315</span>  */</span><span class="WHIT">
<span class='line'>3316</span> </span><span class="NAME">GREUtils.Thread.getMainThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3317</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this._mainThread</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3318</span>         </span><span class="NAME">this._mainThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.getThreadManager</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">mainThread</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3319</span> 
<span class='line'>3320</span>         </span><span class="COMM">// extends magical method to worker thread</span><span class="WHIT">
<span class='line'>3321</span>         </span><span class="COMM">// this._workerThread.dispatchMainThread = GREUtils.Thread.dispatchMainThread;</span><span class="WHIT">
<span class='line'>3322</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3323</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._mainThread</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3324</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3325</span> 
<span class='line'>3326</span> 
<span class='line'>3327</span> </span><span class="COMM">/**
<span class='line'>3328</span>  * dispatchMainThread
<span class='line'>3329</span>  *
<span class='line'>3330</span>  * @public
<span class='line'>3331</span>  * @static
<span class='line'>3332</span>  * @function
<span class='line'>3333</span>  * @return {Object} nsIThreadManager
<span class='line'>3334</span>  * @param {Object} aRunnable
<span class='line'>3335</span>  * @param {Object} aType
<span class='line'>3336</span>  */</span><span class="WHIT">
<span class='line'>3337</span> </span><span class="COMM">/**
<span class='line'>3338</span>  * Dispatches an event to the main thread.
<span class='line'>3339</span>  *
<span class='line'>3340</span>  * The event dispatch mode defaults to DISPATCH_NORMAL, whereby the event is simply
<span class='line'>3341</span>  * queued for later processing. When this mode is specified, dispatch returns
<span class='line'>3342</span>  * immediately after the event is queued.
<span class='line'>3343</span>  *
<span class='line'>3344</span>  * If dispatch mode is set to DISPATCH_SYNC, then the event is dispatched synchronously,
<span class='line'>3345</span>  * and this method does not return until the event has been processed by the main thread.
<span class='line'>3346</span>  *
<span class='line'>3347</span>  * @public
<span class='line'>3348</span>  * @static
<span class='line'>3349</span>  * @function
<span class='line'>3350</span>  * @parameter {nsIRunnable} aRunnable   This is the event to dispatch to the main thread
<span class='line'>3351</span>  * @parameter {int} aType               This is the dispatch mode
<span class='line'>3352</span>  * @return {Object} nsIThreadManager
<span class='line'>3353</span>  * @type                                void
<span class='line'>3354</span>  */</span><span class="WHIT">
<span class='line'>3355</span> </span><span class="NAME">GREUtils.Thread.dispatchMainThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aRunnable</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3356</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mainThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.getMainThread</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3357</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">mainThread.DISPATCH_NORMAL</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3358</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3359</span> 	   </span><span class="NAME">mainThread.dispatch</span><span class="PUNC">(</span><span class="NAME">aRunnable</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3360</span> 	</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3361</span>         </span><span class="NAME">GREUtils.Thread.reportError</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3362</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3363</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3364</span> 
<span class='line'>3365</span> 
<span class='line'>3366</span> </span><span class="COMM">/**
<span class='line'>3367</span>  * dispatchWorkerThread
<span class='line'>3368</span>  *
<span class='line'>3369</span>  * @public
<span class='line'>3370</span>  * @static
<span class='line'>3371</span>  * @function
<span class='line'>3372</span>  * @return {Object} nsIThreadManager
<span class='line'>3373</span>  * @param {Object} workerThread
<span class='line'>3374</span>  * @param {Object} aRunnable
<span class='line'>3375</span>  * @param {Object} aType
<span class='line'>3376</span>  */</span><span class="WHIT">
<span class='line'>3377</span> </span><span class="COMM">/**
<span class='line'>3378</span>  * Dispatches an event to a worker thread.
<span class='line'>3379</span>  *
<span class='line'>3380</span>  * The event dispatch mode defaults to DISPATCH_NORMAL, whereby the event is simply
<span class='line'>3381</span>  * queued for later processing. When this mode is specified, dispatch returns
<span class='line'>3382</span>  * immediately after the event is queued.
<span class='line'>3383</span>  *
<span class='line'>3384</span>  * If dispatch mode is set to DISPATCH_SYNC, then the event is dispatched synchronously,
<span class='line'>3385</span>  * and this method does not return until the event has been processed by the worker thread.
<span class='line'>3386</span>  *
<span class='line'>3387</span>  * @public
<span class='line'>3388</span>  * @static
<span class='line'>3389</span>  * @function
<span class='line'>3390</span>  * @parameter {nsIThread} workerThread  This is the Worker thread to which to dispatch the event
<span class='line'>3391</span>  * @parameter {nsIRunnable} aRunnable   This is the event to dispatch to the Worker thread
<span class='line'>3392</span>  * @parameter {int} aType               This is the dispatch mode
<span class='line'>3393</span>  * @return {Object} nsIThreadManager
<span class='line'>3394</span>  * @type                                void
<span class='line'>3395</span>  */</span><span class="WHIT">
<span class='line'>3396</span> </span><span class="NAME">GREUtils.Thread.dispatchWorkerThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">workerThread</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aRunnable</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3397</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">workerThread.DISPATCH_NORMAL</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3398</span>     </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3399</span>        </span><span class="NAME">workerThread.dispatch</span><span class="PUNC">(</span><span class="NAME">aRunnable</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">aType</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3400</span>     </span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3401</span>         </span><span class="NAME">GREUtils.Thread.reportError</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3402</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3403</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3404</span> 
<span class='line'>3405</span> 
<span class='line'>3406</span> </span><span class="COMM">/**
<span class='line'>3407</span>  * Creates a new thread the first time this method is invoked; this thread will be
<span class='line'>3408</span>  * returned upon subsequent getWorkerThread() calls.
<span class='line'>3409</span>  *
<span class='line'>3410</span>  * @public
<span class='line'>3411</span>  * @static
<span class='line'>3412</span>  * @function
<span class='line'>3413</span>  * @return {Object} nsIThread           The worker thread
<span class='line'>3414</span>  * @type                                nsIThread
<span class='line'>3415</span>  */</span><span class="WHIT">
<span class='line'>3416</span> </span><span class="NAME">GREUtils.Thread.getWorkerThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3417</span>     </span><span class="COMM">// get presist work thread</span><span class="WHIT">
<span class='line'>3418</span>     </span><span class="COMM">// will not create new worker thread</span><span class="WHIT">
<span class='line'>3419</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this._workerThread</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3420</span>         </span><span class="NAME">this._workerThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.getThreadManager</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">newThread</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3421</span> 
<span class='line'>3422</span> 		</span><span class="COMM">// extends magical method to worker thread</span><span class="WHIT">
<span class='line'>3423</span>         </span><span class="COMM">// this._workerThread.dispatchMainThread = GREUtils.Thread.dispatchMainThread;</span><span class="WHIT">
<span class='line'>3424</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3425</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._workerThread</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3426</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3427</span> 
<span class='line'>3428</span> 
<span class='line'>3429</span> </span><span class="COMM">/**
<span class='line'>3430</span>  * Creates a new worker thread. Unlike getWorkerThread(), a new thread is created
<span class='line'>3431</span>  * each time this method is called.
<span class='line'>3432</span>  *
<span class='line'>3433</span>  * @public
<span class='line'>3434</span>  * @static
<span class='line'>3435</span>  * @function
<span class='line'>3436</span>  * @return {Object} nsIThread           The new worker thread
<span class='line'>3437</span>  * @type                                nsIThread
<span class='line'>3438</span>  */</span><span class="WHIT">
<span class='line'>3439</span> </span><span class="NAME">GREUtils.Thread.createWorkerThread</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3440</span>     </span><span class="COMM">// create new worker thread</span><span class="WHIT">
<span class='line'>3441</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">worker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.getThreadManager</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">newThread</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3442</span> 
<span class='line'>3443</span> 	</span><span class="COMM">// extends magical method to worker thread</span><span class="WHIT">
<span class='line'>3444</span> 	</span><span class="COMM">//worker.dispatchMainThread = GREUtils.Thread.dispatchMainThread;</span><span class="WHIT">
<span class='line'>3445</span> 
<span class='line'>3446</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">worker</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3447</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3448</span> 
<span class='line'>3449</span> 
<span class='line'>3450</span> </span><span class="COMM">/**
<span class='line'>3451</span>  * CallbackRunnableAdapter
<span class='line'>3452</span>  *
<span class='line'>3453</span>  * @public
<span class='line'>3454</span>  * @class
<span class='line'>3455</span>  * @param {Object} func
<span class='line'>3456</span>  * @param {Object} data
<span class='line'>3457</span>  */</span><span class="WHIT">
<span class='line'>3458</span> </span><span class="NAME">GREUtils.Thread.CallbackRunnableAdapter</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">func</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3459</span> 	</span><span class="NAME">this._func</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3460</span> 	</span><span class="NAME">this._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3461</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3462</span> 
<span class='line'>3463</span> </span><span class="NAME">GREUtils.Thread.CallbackRunnableAdapter.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3464</span> 
<span class='line'>3465</span>         </span><span class="NAME">get</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3466</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._func</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3467</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3468</span> 
<span class='line'>3469</span>         </span><span class="NAME">set</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">(</span><span class="NAME">func</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3470</span>             </span><span class="NAME">this._func</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">func</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3471</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3472</span> 
<span class='line'>3473</span>         </span><span class="NAME">get</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3474</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3475</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3476</span> 
<span class='line'>3477</span>         </span><span class="NAME">set</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3478</span>             </span><span class="NAME">this._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3479</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3480</span> 
<span class='line'>3481</span>         </span><span class="NAME">run</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3482</span> 			</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3483</span>                  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.func</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3484</span> 				 	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">this.func</span><span class="PUNC">(</span><span class="NAME">this.data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3485</span> 					</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">this.func</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3486</span> 				 </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3487</span>              </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3488</span>                 </span><span class="NAME">Components.utils.reportError</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3489</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3490</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3491</span> 
<span class='line'>3492</span>         </span><span class="NAME">QueryInterface</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">iid</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3493</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">iid.equals</span><span class="PUNC">(</span><span class="NAME">Components.Interfaces.nsIRunnable</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">iid.equals</span><span class="PUNC">(</span><span class="NAME">Components.Interfaces.nsISupports</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3494</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3495</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3496</span>             </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">Components.results.NS_ERROR_NO_INTERFACE</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3497</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3498</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3499</span> 
<span class='line'>3500</span> 
<span class='line'>3501</span> </span><span class="COMM">/**
<span class='line'>3502</span>  * WorkerRunnableAdapter
<span class='line'>3503</span>  *
<span class='line'>3504</span>  * @public
<span class='line'>3505</span>  * @class
<span class='line'>3506</span>  * @param {Object} func
<span class='line'>3507</span>  * @param {Object} callback
<span class='line'>3508</span>  * @param {Object} data
<span class='line'>3509</span>  */</span><span class="WHIT">
<span class='line'>3510</span> </span><span class="NAME">GREUtils.Thread.WorkerRunnableAdapter</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">func</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3511</span>     </span><span class="NAME">this._func</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3512</span> 	</span><span class="NAME">this._callback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3513</span>     </span><span class="NAME">this._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3514</span> 
<span class='line'>3515</span>     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3516</span>         </span><span class="NAME">this._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3517</span> 		</span><span class="NAME">this._callback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3518</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3519</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3520</span> 
<span class='line'>3521</span> </span><span class="NAME">GREUtils.Thread.WorkerRunnableAdapter.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3522</span> 
<span class='line'>3523</span>         </span><span class="NAME">get</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3524</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._func</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3525</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3526</span> 
<span class='line'>3527</span>         </span><span class="NAME">set</span><span class="WHIT"> </span><span class="NAME">func</span><span class="PUNC">(</span><span class="NAME">func</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3528</span>             </span><span class="NAME">this._func</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">func</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3529</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3530</span> 
<span class='line'>3531</span>         </span><span class="NAME">get</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3532</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._callback</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3533</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3534</span> 
<span class='line'>3535</span>         </span><span class="NAME">set</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3536</span>             </span><span class="NAME">this._callback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3537</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3538</span> 
<span class='line'>3539</span>         </span><span class="NAME">get</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3540</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3541</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3542</span> 
<span class='line'>3543</span>         </span><span class="NAME">set</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3544</span>             </span><span class="NAME">this._data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3545</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3546</span> 
<span class='line'>3547</span>         </span><span class="NAME">run</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3548</span>             </span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3549</span> 				</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3550</span>                  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.func</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3551</span>                     </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.func</span><span class="PUNC">(</span><span class="NAME">this.data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3552</span>                     </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.func</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3553</span>                  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3554</span> 
<span class='line'>3555</span>                 </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3556</span> 					</span><span class="NAME">GREUtils.Thread.dispatchMainThread</span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.CallbackRunnableAdapter</span><span class="PUNC">(</span><span class="NAME">this.callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3557</span> 				</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3558</span>             </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3559</span>                 </span><span class="NAME">Components.utils.reportError</span><span class="PUNC">(</span><span class="NAME">err</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3560</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3561</span> 
<span class='line'>3562</span>         </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3563</span> 
<span class='line'>3564</span>         </span><span class="NAME">QueryInterface</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">iid</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3565</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">iid.equals</span><span class="PUNC">(</span><span class="NAME">Components.Interfaces.nsIRunnable</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">iid.equals</span><span class="PUNC">(</span><span class="NAME">Components.Interfaces.nsISupports</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3566</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3567</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3568</span>             </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="NAME">Components.results.NS_ERROR_NO_INTERFACE</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3569</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3570</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3571</span> 
<span class='line'>3572</span> 
<span class='line'>3573</span> </span><span class="COMM">/**
<span class='line'>3574</span>  * createWorkerThreadAdapter
<span class='line'>3575</span>  *
<span class='line'>3576</span>  * @public
<span class='line'>3577</span>  * @static
<span class='line'>3578</span>  * @function
<span class='line'>3579</span>  * @param {Object} workerFunc
<span class='line'>3580</span>  * @param {Object} callbackFunc
<span class='line'>3581</span>  * @param {Object} data
<span class='line'>3582</span>  */</span><span class="WHIT">
<span class='line'>3583</span> </span><span class="NAME">GREUtils.Thread.createWorkerThreadAdapter</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">workerFunc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callbackFunc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3584</span> 
<span class='line'>3585</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">GREUtils.Thread.WorkerRunnableAdapter</span><span class="PUNC">(</span><span class="NAME">workerFunc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callbackFunc</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3586</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3587</span> </span><span class="COMM">/*
<span class='line'>3588</span>  * GREUtils - is simple and easy use APIs libraries for GRE (Gecko Runtime Environment).
<span class='line'>3589</span>  *
<span class='line'>3590</span>  * Copyright (c) 2007 Rack Lin (racklin@gmail.com)
<span class='line'>3591</span>  *
<span class='line'>3592</span>  * $Date: 2007-09-16 23:42:06 -0400 (Sun, 16 Sep 2007) $
<span class='line'>3593</span>  * $Rev: 1 $
<span class='line'>3594</span>  */</span><span class="WHIT">
<span class='line'>3595</span> </span><span class="COMM">/**
<span class='line'>3596</span>  *  GREUtils - is simple and easy use APIs libraries for GRE (Gecko Runtime Environment).
<span class='line'>3597</span>  * Controller and CommandDispatcher Helper
<span class='line'>3598</span>  */</span><span class="WHIT">
<span class='line'>3599</span> </span><span class="NAME">GREUtils.ControllerHelper</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.extend</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3600</span> 
<span class='line'>3601</span>     </span><span class="COMM">/**
<span class='line'>3602</span>      * Append Controller to Window Controllers.
<span class='line'>3603</span>      * Then call Controller's init method
<span class='line'>3604</span>      *
<span class='line'>3605</span>      * @method
<span class='line'>3606</span>      * @id ControllerHelper.appendController
<span class='line'>3607</span>      * @alias GREUtils.ControllerHelper.appendController
<span class='line'>3608</span>      * @param {Object} controller
<span class='line'>3609</span>      */</span><span class="WHIT">
<span class='line'>3610</span>     </span><span class="NAME">appendController</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">controller</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3611</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">controller</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">window.controllers.appendController</span><span class="PUNC">(</span><span class="NAME">controller</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3612</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">app</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3613</span> 
<span class='line'>3614</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">controller.init</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3615</span>             </span><span class="NAME">controller.init</span><span class="PUNC">(</span><span class="NAME">app</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3616</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3617</span>     </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3618</span> 
<span class='line'>3619</span>     </span><span class="COMM">/**
<span class='line'>3620</span>      * Call CommandDispatcher to run Command By CommandName
<span class='line'>3621</span>      *
<span class='line'>3622</span>      * @method
<span class='line'>3623</span>      * @id ControllerHelper.doCommand
<span class='line'>3624</span>      * @alias GREUtils.ControllerHelper.doCommand
<span class='line'>3625</span>      * @param {String} sCmd
<span class='line'>3626</span>      */</span><span class="WHIT">
<span class='line'>3627</span>     </span><span class="NAME">doCommand</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3628</span> 		</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3629</span> 	        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">cmdDispatcher</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.commandDispatcher</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">top.document.commandDispatcher</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.controllers</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3630</span> 	        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">controller</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">cmdDispatcher.getControllerForCommand</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3631</span> 	
<span class='line'>3632</span> 	        </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">controller</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">controller.doCommand</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3633</span> 	
<span class='line'>3634</span> 	        </span><span class="COMM">// try window controller</span><span class="WHIT">
<span class='line'>3635</span> 	        </span><span class="NAME">controller</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">window.controllers.getControllerForCommand</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3636</span> 	        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">controller</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">controller.isCommandEnabled</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">controller.doCommand</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3637</span> 		</span><span class="PUNC">}</span><span class="KEYW">catch</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3638</span> 			</span><span class="NAME">GREUtils.log</span><span class="PUNC">(</span><span class="STRN">'[Error] GREUtils.ControllerHelper.doCommand: '</span><span class="PUNC">+</span><span class="NAME">e.message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3639</span> 		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3640</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3641</span> 
<span class='line'>3642</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3643</span> 
<span class='line'>3644</span> </span><span class="COMM">/**
<span class='line'>3645</span>  * ControllerAdapter
<span class='line'>3646</span>  *
<span class='line'>3647</span>  * @classDescription ControllerAdapter
<span class='line'>3648</span>  * @id ControllerAdapter
<span class='line'>3649</span>  * @alias GREUtils.ControllerAdapter
<span class='line'>3650</span>  */</span><span class="WHIT">
<span class='line'>3651</span> </span><span class="NAME">GREUtils.ControllerAdapter</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">GREUtils.extend</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3652</span>     </span><span class="NAME">_app</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3653</span>     </span><span class="NAME">_privateCommands</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="STRN">'_privateCommands'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'_app'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'init'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'supportsCommand'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'isCommandEnabled'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'doCommand'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'onEvent'</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3654</span> 
<span class='line'>3655</span>     </span><span class="COMM">/**
<span class='line'>3656</span>      * Controller Default Init method
<span class='line'>3657</span>      *
<span class='line'>3658</span>      * Normally don't need to override it.
<span class='line'>3659</span>      *
<span class='line'>3660</span>      * @method
<span class='line'>3661</span>      * @id ControllerHelper.init
<span class='line'>3662</span>      * @alias GREUtils.ControllerHelper.init
<span class='line'>3663</span>      * @param {Object} aApp
<span class='line'>3664</span>      */</span><span class="WHIT">
<span class='line'>3665</span>     </span><span class="NAME">init</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">aApp</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3666</span>         </span><span class="NAME">this._app</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">aApp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3667</span>     </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3668</span> 
<span class='line'>3669</span>     </span><span class="COMM">/**
<span class='line'>3670</span>      * Controller Support Command
<span class='line'>3671</span>      *
<span class='line'>3672</span>      * Normally not need to override it.
<span class='line'>3673</span>      *
<span class='line'>3674</span>      * @method
<span class='line'>3675</span>      * @id ControllerHelper.supportsCommand
<span class='line'>3676</span>      * @alias GREUtils.ControllerHelper.supportsCommand
<span class='line'>3677</span>      * @param {String} sCmd
<span class='line'>3678</span>      */</span><span class="WHIT">
<span class='line'>3679</span>     </span><span class="NAME">supportsCommand</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3680</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">this._privateCommands</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">[</span><span class="NAME">sCmd</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3681</span>             </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3682</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3683</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3684</span>     </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3685</span> 
<span class='line'>3686</span>     </span><span class="COMM">/**
<span class='line'>3687</span>      * Controller isCommandEnabled
<span class='line'>3688</span>      *
<span class='line'>3689</span>      * @method
<span class='line'>3690</span>      * @id ControllerHelper.isCommandEnabled
<span class='line'>3691</span>      * @alias GREUtils.ControllerHelper.isCommandEnabled
<span class='line'>3692</span>      * @param {String} sCmd
<span class='line'>3693</span>      * @return {Boolean}
<span class='line'>3694</span>      */</span><span class="WHIT">
<span class='line'>3695</span>     </span><span class="NAME">isCommandEnabled</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3696</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3697</span>     </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3698</span> 
<span class='line'>3699</span>     </span><span class="COMM">/**
<span class='line'>3700</span>      * Controller doCommand
<span class='line'>3701</span>      *
<span class='line'>3702</span>      * Normally not need to override it.
<span class='line'>3703</span>      *
<span class='line'>3704</span>      * @method
<span class='line'>3705</span>      * @id ControllerHelper.doCommand
<span class='line'>3706</span>      * @alias GREUtils.ControllerHelper.doCommand
<span class='line'>3707</span>      * @param {String} sCmd
<span class='line'>3708</span>      */</span><span class="WHIT">
<span class='line'>3709</span>     </span><span class="NAME">doCommand</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3710</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">this._privateCommands</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">[</span><span class="NAME">sCmd</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3711</span>             </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.isCommandEnabled</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">[</span><span class="NAME">sCmd</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3712</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3713</span>     </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>3714</span> 
<span class='line'>3715</span>     </span><span class="COMM">/**
<span class='line'>3716</span>      * Controller onEvent
<span class='line'>3717</span>      *
<span class='line'>3718</span>      * Normally not need to override it.
<span class='line'>3719</span>      *
<span class='line'>3720</span>      * @method
<span class='line'>3721</span>      * @id ControllerHelper.onEvent
<span class='line'>3722</span>      * @alias GREUtils.ControllerHelper.onEvent
<span class='line'>3723</span>      * @param {String} sCmd
<span class='line'>3724</span>      */</span><span class="WHIT">
<span class='line'>3725</span>     </span><span class="NAME">onEvent</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3726</span>         </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">[</span><span class="NAME">sCmd</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'function'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>3727</span>             </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.isCommandEnabled</span><span class="PUNC">(</span><span class="NAME">sCmd</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">[</span><span class="NAME">sCmd</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3728</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3729</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>3730</span> 
<span class='line'>3731</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>3732</span> </span></pre></body></html>